From 08ba394b1199797e3f0be7efead66e0b5393b5c3 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Fri, 24 May 2013 17:19:51 +0300 Subject: Disable drag&drop when source or target component is disabled, re-implementation of 6.8 fix for #11801 Change-Id: Iacd167ad7075620dae59ff2c7789efaf32521c59 --- server/src/com/vaadin/server/DragAndDropService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index 5a54b5ae3a..38c055eb1a 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -64,6 +64,16 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public void changeVariables(Object source, Map variables) { Object owner = variables.get("dhowner"); + final Component sourceComponent = (Component) variables + .get("component"); + if (sourceComponent != null && !sourceComponent.isEnabled()) { + // source component not supposed to be enabled + getLogger().warning( + "Client dropped from " + sourceComponent + + " even though it's disabled"); + return; + } + // Validate drop handler owner if (!(owner instanceof DropTarget)) { getLogger() @@ -74,6 +84,15 @@ public class DragAndDropService implements VariableOwner, ClientConnector { // owner cannot be null here DropTarget dropTarget = (DropTarget) owner; + + if (!dropTarget.isEnabled()) { + getLogger() + .warning( + "Client dropped on " + owner + + " even though it's disabled"); + return; + } + lastVisitId = (Integer) variables.get("visitId"); // request may be dropRequest or request during drag operation (commonly -- cgit v1.2.3 From b01427a456323317b7062b83dd38cc31c103b7ad Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 16 May 2013 09:36:37 +0000 Subject: Change field types from LinkedHashSet back to HashSet to retain binary compatibility (#11432) svn changeset:25964/svn branch:6.8 Change-Id: Iddf0fa7de10a788e1a51e006e92ed3976a39a30b --- server/src/com/vaadin/event/ActionManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/event/ActionManager.java b/server/src/com/vaadin/event/ActionManager.java index ce3e27d539..8d7a64b364 100644 --- a/server/src/com/vaadin/event/ActionManager.java +++ b/server/src/com/vaadin/event/ActionManager.java @@ -15,6 +15,7 @@ */ package com.vaadin.event; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; @@ -43,11 +44,15 @@ public class ActionManager implements Action.Container, Action.Handler, private static final long serialVersionUID = 1641868163608066491L; - /** List of action handlers */ - protected LinkedHashSet ownActions = null; + /** + * List of action handlers. Guaranteed to keep the original insertion order. + */ + protected HashSet ownActions = null; - /** List of action handlers */ - protected LinkedHashSet actionHandlers = null; + /** + * List of action handlers. Guaranteed to keep the original insertion order. + */ + protected HashSet actionHandlers = null; /** Action mapper */ protected KeyMapper actionMapper = null; -- cgit v1.2.3 From 9100cfc70255f95982f230f29ef72dffe46027d5 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 5 Jun 2013 15:04:25 +0300 Subject: Do not rely on broken javadoc features for default values (#11970) Change-Id: Ic904a33e31b54da7c1324c70b792c38ee1b56fac --- .../com/vaadin/annotations/VaadinServletConfiguration.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/annotations/VaadinServletConfiguration.java b/server/src/com/vaadin/annotations/VaadinServletConfiguration.java index 38e3ff2ef0..e65869c27a 100644 --- a/server/src/com/vaadin/annotations/VaadinServletConfiguration.java +++ b/server/src/com/vaadin/annotations/VaadinServletConfiguration.java @@ -84,8 +84,7 @@ public @interface VaadinServletConfiguration { /** * The time resources can be cached in the browser, in seconds. The default - * value is - * {@value DefaultDeploymentConfiguration#DEFAULT_RESOURCE_CACHE_TIME}. + * value is 3600 seconds, i.e. one hour. * * @return the resource cache time * @@ -96,8 +95,8 @@ public @interface VaadinServletConfiguration { /** * The number of seconds between heartbeat requests of a UI, or a - * non-positive number if heartbeat is disabled. The default value is - * {@value DefaultDeploymentConfiguration#DEFAULT_HEARTBEAT_INTERVAL}. + * non-positive number if heartbeat is disabled. The default value is 300 + * seconds, i.e. 5 minutes. * * @return the time between heartbeats * @@ -109,7 +108,7 @@ public @interface VaadinServletConfiguration { /** * Whether a session should be closed when all its open UIs have been idle * for longer than its configured maximum inactivity time. The default value - * is {@value DefaultDeploymentConfiguration#DEFAULT_CLOSE_IDLE_SESSIONS}. + * is false. * * @return true if UIs and sessions receiving only heartbeat requests are * eventually closed; false if heartbeat requests extend UI and @@ -122,7 +121,7 @@ public @interface VaadinServletConfiguration { /** * The default widgetset to use for the servlet. The default value is - * {@value VaadinServlet#DEFAULT_WIDGETSET}. + * com.vaadin.DefaultWidgetSet. * * @return the default widgetset name */ -- cgit v1.2.3 From fad7bf7a791db16349467ccbc508d0e472330fa0 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 5 Jun 2013 18:21:44 +0300 Subject: Remove DEFAULT constant as an annotation enum cannot use it (#11966) Change-Id: I41630fec5c40c50a2925499d1f1ba23149ab0de1 --- server/src/com/vaadin/annotations/Push.java | 2 +- shared/src/com/vaadin/shared/ui/ui/Transport.java | 10 ---------- shared/src/com/vaadin/shared/ui/ui/UIState.java | 5 +++-- 3 files changed, 4 insertions(+), 13 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/annotations/Push.java b/server/src/com/vaadin/annotations/Push.java index d5e42d6f60..9965d535ba 100644 --- a/server/src/com/vaadin/annotations/Push.java +++ b/server/src/com/vaadin/annotations/Push.java @@ -54,6 +54,6 @@ public @interface Push { * * @return the transport type to use */ - public Transport transport() default Transport.DEFAULT; + public Transport transport() default Transport.WEBSOCKET; } diff --git a/shared/src/com/vaadin/shared/ui/ui/Transport.java b/shared/src/com/vaadin/shared/ui/ui/Transport.java index 69d713bcca..ea641c0a3c 100644 --- a/shared/src/com/vaadin/shared/ui/ui/Transport.java +++ b/shared/src/com/vaadin/shared/ui/ui/Transport.java @@ -32,16 +32,6 @@ public enum Transport { */ STREAMING("streaming"); - /** - * The default transport mechanism for push - */ - public static final Transport DEFAULT = Transport.WEBSOCKET; - - /** - * The default fallback transport mechanism for push - */ - public static final Transport DEFAULT_FALLBACK = Transport.STREAMING; - private String identifier; private Transport(String identifier) { diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java index e19a87ada9..8d042a835f 100644 --- a/shared/src/com/vaadin/shared/ui/ui/UIState.java +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -55,9 +55,10 @@ public class UIState extends TabIndexState { public PushMode mode = PushMode.DISABLED; public Map parameters = new HashMap(); { - parameters.put(TRANSPORT_PARAM, Transport.DEFAULT.getIdentifier()); + parameters + .put(TRANSPORT_PARAM, Transport.WEBSOCKET.getIdentifier()); parameters.put(FALLBACK_TRANSPORT_PARAM, - Transport.DEFAULT_FALLBACK.getIdentifier()); + Transport.STREAMING.getIdentifier()); } } -- cgit v1.2.3 From 8eb567eb3e0650fcbaa7296e6ff4e42e8000e4ce Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 5 Jun 2013 16:20:27 +0300 Subject: Make UI.pushConnection transient to prevent null resource after deserialization (#11809) * PushConnection is not Serializable anymore * AtmospherePushConnection fields are not transient * UI.setSession calls setPushConnection(null) instead of pushConnection.disconnect() * pushConnection.disconnect() asserts isConnected() * If UI has a push connection, it should now always have isConnected() == true Change-Id: I3c2e877b8e723b7cc2993cacd620920aecdef5fb --- .../communication/AtmospherePushConnection.java | 26 ++++++---------------- .../server/communication/PushConnection.java | 12 +++++----- .../vaadin/server/communication/PushHandler.java | 23 +++++++++---------- server/src/com/vaadin/ui/UI.java | 24 +++++++++++--------- 4 files changed, 37 insertions(+), 48 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 9e57ccb45d..e325550c4b 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -93,12 +93,13 @@ public class AtmospherePushConnection implements PushConnection { } private UI ui; - private transient AtmosphereResource resource; - private transient Future outgoingMessage; - private transient FragmentedMessage incomingMessage; + private AtmosphereResource resource; + private Future outgoingMessage; + private FragmentedMessage incomingMessage; - public AtmospherePushConnection(UI ui) { + public AtmospherePushConnection(UI ui, AtmosphereResource resource) { this.ui = ui; + this.resource = resource; } @Override @@ -176,21 +177,6 @@ public class AtmospherePushConnection implements PushConnection { } } - /** - * Associates this connection with the given AtmosphereResource. If there is - * a push pending, commits it. - * - * @param resource - * The AtmosphereResource representing the push channel. - * @throws IOException - */ - protected void connect(AtmosphereResource resource) throws IOException { - this.resource = resource; - } - - /** - * Returns whether this connection is currently open. - */ @Override public boolean isConnected() { return resource != null @@ -215,6 +201,8 @@ public class AtmospherePushConnection implements PushConnection { @Override public void disconnect() { + assert isConnected(); + if (outgoingMessage != null) { // Wait for the last message to be sent before closing the // connection (assumes that futures are completed in order) diff --git a/server/src/com/vaadin/server/communication/PushConnection.java b/server/src/com/vaadin/server/communication/PushConnection.java index bb88998402..7f78d1d48e 100644 --- a/server/src/com/vaadin/server/communication/PushConnection.java +++ b/server/src/com/vaadin/server/communication/PushConnection.java @@ -16,8 +16,6 @@ package com.vaadin.server.communication; -import java.io.Serializable; - import com.vaadin.ui.UI; /** @@ -27,18 +25,20 @@ import com.vaadin.ui.UI; * @author Vaadin Ltd * @since 7.1 */ -public interface PushConnection extends Serializable { +public interface PushConnection { /** - * Pushes pending state changes and client RPC calls to the client. It is - * NOT safe to invoke this method if not holding the session lock. + * Pushes pending state changes and client RPC calls to the client. Cannot + * be called if {@link #isConnected()} is false. It is NOT safe to invoke + * this method if not holding the session lock. *

* This is internal API; please use {@link UI#push()} instead. */ public void push(); /** - * Disconnects the connection. + * Closes the connection. Cannot be called if {@link #isConnected()} is + * false. */ public void disconnect(); diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 7efcb8fd8c..6b853063a7 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -109,8 +109,7 @@ public class PushHandler implements AtmosphereHandler { resource.suspend(); AtmospherePushConnection connection = new AtmospherePushConnection( - ui); - connection.connect(resource); + ui, resource); ui.setPushConnection(connection); } @@ -305,12 +304,9 @@ public class PushHandler implements AtmosphereHandler { private static AtmospherePushConnection getConnectionForUI(UI ui) { PushConnection pushConnection = ui.getPushConnection(); if (pushConnection instanceof AtmospherePushConnection) { - AtmospherePushConnection apc = (AtmospherePushConnection) pushConnection; - if (apc.isConnected()) { - return apc; - } + assert pushConnection.isConnected(); + return (AtmospherePushConnection) pushConnection; } - return null; } @@ -374,11 +370,14 @@ public class PushHandler implements AtmosphereHandler { */ private static void sendRefreshAndDisconnect(AtmosphereResource resource) throws IOException { - AtmospherePushConnection connection = new AtmospherePushConnection(null); - connection.connect(resource); - connection.sendMessage(VaadinService.createCriticalNotificationJSON( - null, null, null, null)); - connection.disconnect(); + AtmospherePushConnection connection = new AtmospherePushConnection( + null, resource); + try { + connection.sendMessage(VaadinService + .createCriticalNotificationJSON(null, null, null, null)); + } finally { + connection.disconnect(); + } } private static final Logger getLogger() { diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index fa38666dc2..6c9551ea81 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -411,12 +411,9 @@ public abstract class UI extends AbstractSingleComponentContainer implements } else { if (session == null) { detach(); - if (pushConnection != null && pushConnection.isConnected()) { - // Close the push connection when UI is detached. Otherwise - // the push connection and possibly VaadinSession will live - // on. - pushConnection.disconnect(); - } + // Close the push connection when UI is detached. Otherwise the + // push connection and possibly VaadinSession will live on. + setPushConnection(null); } this.session = session; } @@ -536,7 +533,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements private Navigator navigator; - private PushConnection pushConnection = null; + private transient PushConnection pushConnection = null; private boolean hasPendingPush = false; @@ -1072,7 +1069,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements boolean sessionExpired = (session == null || session.isClosing()); getRpcProxy(UIClientRpc.class).uiClosed(sessionExpired); - if (getPushConnection() != null && getPushConnection().isConnected()) { + if (getPushConnection() != null) { // Push the Rpc to the client. The connection will be closed when // the UI is detached and cleaned up. getPushConnection().push(); @@ -1342,19 +1339,24 @@ public abstract class UI extends AbstractSingleComponentContainer implements /** * Returns the internal push connection object used by this UI. This method - * should only be called by the framework. + * should only be called by the framework. If the returned PushConnection is + * not null, it is guaranteed to have {@code isConnected() == true}. */ public PushConnection getPushConnection() { + assert (pushConnection == null || pushConnection.isConnected()); return pushConnection; } /** * Sets the internal push connection object used by this UI. This method - * should only be called by the framework. + * should only be called by the framework. If {@pushConnection} is not null, + * its {@code isConnected()} must be true. */ public void setPushConnection(PushConnection pushConnection) { // If pushMode is disabled then there should never be a pushConnection - assert (getPushConfiguration().getPushMode().isEnabled() || pushConnection == null); + assert (pushConnection == null || getPushConfiguration().getPushMode() + .isEnabled()); + assert (pushConnection == null || pushConnection.isConnected()); if (pushConnection == this.pushConnection) { return; -- cgit v1.2.3 From 1b0a214100e6270abea8b9f415a0873de88aab95 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 31 May 2013 09:56:58 +0300 Subject: Pass ConversionException to getConversionError (#11960) Change-Id: I6a25c4e4bfd9fe73f973670583c708503f77f60a --- server/src/com/vaadin/ui/AbstractField.java | 37 +++++++---- .../AbsFieldValueConversionError.java | 72 ++++++++++++++++++++++ 2 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 606bf5fb21..7ac3a57c46 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -751,24 +751,36 @@ public abstract class AbstractField extends AbstractComponent implements return ConverterUtil.convertToModel(fieldValue, (Class) modelType, getConverter(), locale); } catch (ConversionException e) { - throw new ConversionException(getConversionError(modelType), e); + throw new ConversionException(getConversionError(modelType, e), e); } } /** - * Returns the conversion error with {0} replaced by the data source type. + * Returns the conversion error with {0} replaced by the data source type + * and {1} replaced by the exception (localized) message. * + * @since 7.1 * @param dataSourceType - * The type of the data source + * the type of the data source + * @param e + * a conversion exception which can provide additional + * information * @return The value conversion error string with parameters replaced. */ - protected String getConversionError(Class dataSourceType) { - if (dataSourceType == null) { - return getConversionError(); - } else { - return getConversionError().replace("{0}", + protected String getConversionError(Class dataSourceType, + ConversionException e) { + String conversionError = getConversionError(); + + if (dataSourceType != null) { + conversionError = conversionError.replace("{0}", dataSourceType.getSimpleName()); } + if (e != null) { + conversionError = conversionError.replace("{1}", + e.getLocalizedMessage()); + } + + return conversionError; } /** @@ -924,9 +936,9 @@ public abstract class AbstractField extends AbstractComponent implements try { valueToValidate = getConverter().convertToModel(fieldValue, getLocale()); - } catch (Exception e) { - throw new InvalidValueException( - getConversionError(getConverter().getModelType())); + } catch (ConversionException e) { + throw new InvalidValueException(getConversionError( + getConverter().getModelType(), e)); } } @@ -1461,7 +1473,8 @@ public abstract class AbstractField extends AbstractComponent implements /** * Sets the error that is shown if the field value cannot be converted to * the data source type. If {0} is present in the message, it will be - * replaced by the simple name of the data source type. + * replaced by the simple name of the data source type. If {1} is present in + * the message, it will be replaced by the ConversionException message. * * @param valueConversionError * Message to be shown when conversion of the value fails diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java new file mode 100644 index 0000000000..ad762f8931 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java @@ -0,0 +1,72 @@ +package com.vaadin.tests.server.component.abstractfield; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.vaadin.data.Validator.InvalidValueException; +import com.vaadin.data.util.MethodProperty; +import com.vaadin.data.util.converter.Converter.ConversionException; +import com.vaadin.data.util.converter.StringToIntegerConverter; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.ui.TextField; + +public class AbsFieldValueConversionError extends TestCase { + + Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", + 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", + Country.FINLAND)); + + public void testValidateConversionErrorParameters() { + TextField tf = new TextField(); + tf.setConverter(new StringToIntegerConverter()); + tf.setPropertyDataSource(new MethodProperty(paulaBean, "age")); + tf.setConversionError("(Type: {0}) Converter exception message: {1}"); + tf.setValue("abc"); + try { + tf.validate(); + fail(); + } catch (InvalidValueException e) { + Assert.assertEquals( + "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer", + e.getMessage()); + } + + } + + public void testConvertToModelConversionErrorParameters() { + TextField tf = new TextField(); + tf.setConverter(new StringToIntegerConverter()); + tf.setPropertyDataSource(new MethodProperty(paulaBean, "age")); + tf.setConversionError("(Type: {0}) Converter exception message: {1}"); + tf.setValue("abc"); + try { + tf.getConvertedValue(); + fail(); + } catch (ConversionException e) { + Assert.assertEquals( + "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer", + e.getMessage()); + } + + } + + public void testDefaultConversionErrorMessage() { + TextField tf = new TextField(); + tf.setConverter(new StringToIntegerConverter()); + tf.setPropertyDataSource(new MethodProperty(paulaBean, "age")); + tf.setValue("abc"); + + try { + tf.validate(); + fail(); + } catch (InvalidValueException e) { + Assert.assertEquals("Could not convert value to Integer", + e.getMessage()); + } + + } +} -- cgit v1.2.3 From da29e2b1a50b3e8d7240e9c76d829042772f65ef Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 7 Jun 2013 00:29:12 +0300 Subject: Fixed serialization issues Change-Id: I5dc1f2dc061c4b6bb6d00040b972802df97d3f89 --- server/src/com/vaadin/server/LocaleService.java | 3 ++- server/src/com/vaadin/server/Page.java | 2 +- server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/LocaleService.java b/server/src/com/vaadin/server/LocaleService.java index 347c4da5c6..031ceb433c 100644 --- a/server/src/com/vaadin/server/LocaleService.java +++ b/server/src/com/vaadin/server/LocaleService.java @@ -19,6 +19,7 @@ */ package com.vaadin.server; +import java.io.Serializable; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.text.SimpleDateFormat; @@ -37,7 +38,7 @@ import com.vaadin.ui.UI; * @since 7.1 * @author Vaadin Ltd */ -public class LocaleService { +public class LocaleService implements Serializable { private UI ui; diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 11553527e0..4dd7d34e38 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -306,7 +306,7 @@ public class Page implements Serializable { } } - private static interface InjectedStyle { + private static interface InjectedStyle extends Serializable { public void paint(int id, PaintTarget target) throws PaintException; } diff --git a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java index af6d9ed732..63168e3c91 100644 --- a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java +++ b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java @@ -60,6 +60,10 @@ public class TestClassesSerializable extends TestCase { "com\\.vaadin\\.sass.*", // "com\\.vaadin\\.testbench.*", // "com\\.vaadin\\.util\\.CurrentInstance\\$1", // + "com\\.vaadin\\.server\\.communication\\.PushConnection", // + "com\\.vaadin\\.server\\.communication\\.AtmospherePushConnection", // + "com\\.vaadin\\.util\\.ConnectorHelper", // + "com\\.vaadin\\.server\\.VaadinSession$FutureAccess", // }; /** -- cgit v1.2.3 From e7201fd30803dbbd231c9a26745b21d5b807abc0 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 6 Jun 2013 12:01:37 +0300 Subject: Allow using element resize listeners from javascript connectors (#11996) Change-Id: I97b280c2e260752be87ce85d2eda81ec4f14d4fe --- .../vaadin/client/JavaScriptConnectorHelper.java | 81 +++++++++++++++++- .../com/vaadin/ui/AbstractJavaScriptComponent.java | 10 +++ .../JavaScriptResizeListener.html | 81 ++++++++++++++++++ .../JavaScriptResizeListener.java | 96 ++++++++++++++++++++++ .../javascriptcomponent/ResizeJsConnector.js | 23 ++++++ 5 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html create mode 100644 uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java create mode 100644 uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js (limited to 'server/src/com/vaadin') diff --git a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java index b144603be0..52d2eeb6dc 100644 --- a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java +++ b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java @@ -25,11 +25,13 @@ import java.util.Set; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; +import com.google.gwt.dom.client.Element; import com.google.gwt.json.client.JSONArray; -import com.google.gwt.user.client.Element; import com.vaadin.client.communication.JavaScriptMethodInvocation; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; +import com.vaadin.client.ui.layout.ElementResizeEvent; +import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.JavaScriptConnectorState; import com.vaadin.shared.communication.MethodInvocation; @@ -42,6 +44,7 @@ public class JavaScriptConnectorHelper { private final Map rpcObjects = new HashMap(); private final Map> rpcMethods = new HashMap>(); + private final Map> resizeListeners = new HashMap>(); private JavaScriptObject connectorWrapper; private int tag; @@ -204,9 +207,71 @@ public class JavaScriptConnectorHelper { 'translateVaadinUri': $entry(function(uri) { return c.@com.vaadin.client.ApplicationConnection::translateVaadinUri(Ljava/lang/String;)(uri); }), + 'addResizeListener': function(element, resizeListener) { + if (!element || element.nodeType != 1) throw "element must be defined"; + if (typeof resizeListener != "function") throw "resizeListener must be defined"; + $entry(h.@com.vaadin.client.JavaScriptConnectorHelper::addResizeListener(*)).call(h, element, resizeListener); + }, + 'removeResizeListener': function(element, resizeListener) { + if (!element || element.nodeType != 1) throw "element must be defined"; + if (typeof resizeListener != "function") throw "resizeListener must be defined"; + $entry(h.@com.vaadin.client.JavaScriptConnectorHelper::removeResizeListener(*)).call(h, element, resizeListener); + } }; }-*/; + // Called from JSNI to add a listener + private void addResizeListener(Element element, + final JavaScriptObject callbackFunction) { + Map elementListeners = resizeListeners + .get(element); + if (elementListeners == null) { + elementListeners = new HashMap(); + resizeListeners.put(element, elementListeners); + } + + ElementResizeListener listener = elementListeners.get(callbackFunction); + if (listener == null) { + LayoutManager layoutManager = LayoutManager.get(connector + .getConnection()); + listener = new ElementResizeListener() { + @Override + public void onElementResize(ElementResizeEvent e) { + invokeElementResizeCallback(e.getElement(), + callbackFunction); + } + }; + layoutManager.addElementResizeListener(element, listener); + elementListeners.put(callbackFunction, listener); + } + } + + private static native void invokeElementResizeCallback(Element element, + JavaScriptObject callbackFunction) + /*-{ + // Call with a simple event object and 'this' pointing to the global scope + callbackFunction.call($wnd, {'element': element}); + }-*/; + + // Called from JSNI to remove a listener + private void removeResizeListener(Element element, + JavaScriptObject callbackFunction) { + Map listenerMap = resizeListeners + .get(element); + if (listenerMap == null) { + return; + } + + ElementResizeListener listener = listenerMap.remove(callbackFunction); + if (listener != null) { + LayoutManager.get(connector.getConnection()) + .removeElementResizeListener(element, listener); + if (listenerMap.isEmpty()) { + resizeListeners.remove(element); + } + } + } + private native void attachRpcMethod(JavaScriptObject rpc, String iface, String method) /*-{ @@ -377,6 +442,20 @@ public class JavaScriptConnectorHelper { public void onUnregister() { invokeIfPresent(connectorWrapper, "onUnregister"); + + if (!resizeListeners.isEmpty()) { + LayoutManager layoutManager = LayoutManager.get(connector + .getConnection()); + for (Entry> entry : resizeListeners + .entrySet()) { + Element element = entry.getKey(); + for (ElementResizeListener listener : entry.getValue().values()) { + layoutManager + .removeElementResizeListener(element, listener); + } + } + resizeListeners.clear(); + } } private static native void invokeIfPresent( diff --git a/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java b/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java index 0b3da768c9..6769b6e513 100644 --- a/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java +++ b/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java @@ -82,6 +82,16 @@ import com.vaadin.shared.ui.JavaScriptComponentState; *
  • translateVaadinUri(uri) - Translates a Vaadin URI to a URL * that can be used in the browser. This is just way of accessing * {@link com.vaadin.client.ApplicationConnection#translateVaadinUri(String)}
  • + *
  • addResizeListener(element, callbackFunction) - Registers a + * listener that gets notified whenever the size of the provided element + * changes. The listener is called with one parameter: an event object with the + * element property pointing to the element that has been resized. + *
  • removeResizeListener(element, callbackFunction) - + * Unregisters a combination of an element and a listener that has previously + * been registered using addResizeListener. All registered + * listeners are automatically unregistered when this connector is unregistered, + * but this method can be use to to unregister a listener at an earlier point in + * time. * * The connector wrapper also supports these special functions: *
      diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html new file mode 100644 index 0000000000..53af1d4ceb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html @@ -0,0 +1,81 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      New Test
      open/run/com.vaadin.tests.components.javascriptcomponent.JavaScriptResizeListener?restartApplication&debug
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Initial state
      clickvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Initial state
      mouseClickvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]52,4
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Current size is 200 x 50
      clickvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Current size is 100 x 100
      mouseClickvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]69,2
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Listener disabled
      clickvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
      assertTextvaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]Listener disabled
      + + diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java new file mode 100644 index 0000000000..9d0094b833 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java @@ -0,0 +1,96 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.javascriptcomponent; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractJavaScriptComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.CssLayout; + +public class JavaScriptResizeListener extends AbstractTestUI { + + @JavaScript("ResizeJsConnector.js") + public class ResizeJsComponent extends AbstractJavaScriptComponent { + public void setListenerEnabled(boolean enabled) { + callFunction("setListenerEnabled", Boolean.valueOf(enabled)); + } + } + + private final ResizeJsComponent resizeJsComponent = new ResizeJsComponent(); + + private final CssLayout holder = new CssLayout(); + + @Override + protected void setup(VaadinRequest request) { + + addComponent(new Button("Change holder size", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + updateHolderSize(); + } + })); + addComponent(new CheckBox("Listener active") { + { + setImmediate(true); + addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(Property.ValueChangeEvent event) { + resizeJsComponent.setListenerEnabled(event + .getProperty().getValue() == Boolean.TRUE); + } + }); + } + }); + + updateHolderSize(); + addComponent(holder); + + resizeJsComponent.setSizeFull(); + holder.addComponent(resizeJsComponent); + } + + private void updateHolderSize() { + if (holder.getHeight() == 100) { + holder.setHeight("50px"); + } else { + holder.setHeight("100px"); + } + + if (holder.getWidth() == 100) { + holder.setWidth("200px"); + } else { + holder.setWidth("100px"); + } + } + + @Override + protected String getTestDescription() { + return "Test for getting resize events for javascript components"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11996); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js b/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js new file mode 100644 index 0000000000..4e871aa1b7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js @@ -0,0 +1,23 @@ +function com_vaadin_tests_components_javascriptcomponent_JavaScriptResizeListener_ResizeJsComponent() { + var self = this; + var e = this.getElement(); + + var setText = function(text) { + e.innerHTML = text; + } + setText('Initial state'); + + var resizeListener = function(event) { + setText('Current size is ' + event.element.offsetWidth + " x " + event.element.offsetHeight); + }; + + this.setListenerEnabled = function(enabled) { + if (enabled) { + setText("Listener enabled"); + self.addResizeListener(e, resizeListener); + } else { + setText("Listener disabled"); + self.removeResizeListener(e, resizeListener); + } + } +} \ No newline at end of file -- cgit v1.2.3 From e853280aa95e2422821f65da601f780318f2132f Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2013 15:10:29 +0300 Subject: Print warning if in production mode and theme compilation is required (#12031) Change-Id: I59030e7c0133d790f145d31f1614b7e8aaf7c04d --- server/src/com/vaadin/server/VaadinServlet.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 05e3335c00..a3030c9d8d 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -742,11 +742,6 @@ public class VaadinServlet extends HttpServlet implements Constants { private boolean serveOnTheFlyCompiledScss(String filename, HttpServletRequest request, HttpServletResponse response, ServletContext sc) throws IOException { - if (getService().getDeploymentConfiguration().isProductionMode()) { - // This is not meant for production mode. - return false; - } - if (!filename.endsWith(".css")) { return false; } @@ -766,9 +761,21 @@ public class VaadinServlet extends HttpServlet implements Constants { "Requested resource [{0}] not accessible in the VAADIN directory or access to it is forbidden.", filename); response.setStatus(HttpServletResponse.SC_FORBIDDEN); + // Handled, return true so no further processing is done return true; } + if (getService().getDeploymentConfiguration().isProductionMode()) { + // This is not meant for production mode. + getLogger() + .log(Level.INFO, + "Request for {0} not handled by sass compiler while in production mode", + filename); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + // Handled, return true so no further processing is done + return true; + } + synchronized (SCSS_MUTEX) { String realFilename = sc.getRealPath(scssFilename); ScssStylesheet scss = ScssStylesheet.get(realFilename); -- cgit v1.2.3 From d9becf9523fdd71abb1b93072a76df163b9dd2c0 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2013 14:18:33 +0300 Subject: Use vaadin-atmosphere without slf4j dependency (#11765) Change-Id: I78f5dda87957452670c3d86d960b0683c67eb77d --- push/build.xml | 2 +- push/ivy.xml | 4 ++-- server/src/com/vaadin/server/Constants.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/push/build.xml b/push/build.xml index ad27599d36..d09e6766fc 100644 --- a/push/build.xml +++ b/push/build.xml @@ -14,7 +14,7 @@ - + diff --git a/push/ivy.xml b/push/ivy.xml index e2ba3a63f7..d0a60dc1c3 100644 --- a/push/ivy.xml +++ b/push/ivy.xml @@ -27,8 +27,8 @@ - + diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java index 7d3201efdf..0ea9de252a 100644 --- a/server/src/com/vaadin/server/Constants.java +++ b/server/src/com/vaadin/server/Constants.java @@ -65,7 +65,7 @@ public interface Constants { + " Widgetset version: %s\n" + "================================================================="; - static final String REQUIRED_ATMOSPHERE_VERSION = "1.0.13"; + static final String REQUIRED_ATMOSPHERE_VERSION = "1.0.14-2"; static final String INVALID_ATMOSPHERE_VERSION_WARNING = "\n" + "=================================================================\n" -- cgit v1.2.3 From 424af57c0a99bf93066d331fe6a3a870cc44cf24 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2013 19:28:57 +0300 Subject: Move ClientConnector.setParent to Component and Extension (#11777) Change-Id: I1f0b2597f621160329ddc432869277b2758efd52 --- .../com/vaadin/server/AbstractClientConnector.java | 34 ---------------------- .../src/com/vaadin/server/AbstractExtension.java | 33 ++++++++++++++++++++- server/src/com/vaadin/server/ClientConnector.java | 33 --------------------- .../src/com/vaadin/server/DragAndDropService.java | 6 ---- server/src/com/vaadin/server/Extension.java | 21 +++++++++++++ server/src/com/vaadin/ui/AbstractComponent.java | 34 ++++++++++++++++------ server/src/com/vaadin/ui/Component.java | 26 +++++++++++++++++ server/src/com/vaadin/ui/Window.java | 3 +- 8 files changed, 105 insertions(+), 85 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 01f7d9af42..c3101924dd 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -84,8 +84,6 @@ public abstract class AbstractClientConnector implements ClientConnector, private ArrayList extensions = new ArrayList(); - private ClientConnector parent; - /** * The EventRouter used for the event model. */ @@ -563,38 +561,6 @@ public abstract class AbstractClientConnector implements ClientConnector, markAsDirty(); } - @Override - public void setParent(ClientConnector parent) { - - // If the parent is not changed, don't do anything - if (parent == this.parent) { - return; - } - - if (parent != null && this.parent != null) { - throw new IllegalStateException(getClass().getName() - + " already has a parent."); - } - - // Send detach event if the component have been connected to a window - if (isAttached()) { - detach(); - } - - // Connect to new parent - this.parent = parent; - - // Send attach event if connected to an application - if (isAttached()) { - attach(); - } - } - - @Override - public ClientConnector getParent() { - return parent; - } - /* * (non-Javadoc) * diff --git a/server/src/com/vaadin/server/AbstractExtension.java b/server/src/com/vaadin/server/AbstractExtension.java index 00496aed4a..0387ad1b08 100644 --- a/server/src/com/vaadin/server/AbstractExtension.java +++ b/server/src/com/vaadin/server/AbstractExtension.java @@ -33,6 +33,8 @@ public abstract class AbstractExtension extends AbstractClientConnector implements Extension { private boolean previouslyAttached = false; + private ClientConnector parent; + /** * Gets a type that the parent must be an instance of. Override this if the * extension only support certain targets, e.g. if only TextFields can be @@ -69,7 +71,7 @@ public abstract class AbstractExtension extends AbstractClientConnector Class supportedParentType = getSupportedParentType(); if (parent == null || supportedParentType.isInstance(parent)) { - super.setParent(parent); + internalSetParent(parent); previouslyAttached = true; } else { throw new IllegalArgumentException(getClass().getName() @@ -79,4 +81,33 @@ public abstract class AbstractExtension extends AbstractClientConnector } } + /** + * Actually sets the parent and calls required listeners. + * + * @since 7.1 + * @param parent + * The parent to set + */ + private void internalSetParent(ClientConnector parent) { + + // Send a detach event if the component is currently attached + if (isAttached()) { + detach(); + } + + // Connect to new parent + this.parent = parent; + + // Send attach event if the component is now attached + if (isAttached()) { + attach(); + } + + } + + @Override + public ClientConnector getParent() { + return parent; + } + } diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 9e328bb6ef..3c06d5743c 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -27,8 +27,6 @@ import com.vaadin.event.ConnectorEvent; import com.vaadin.event.ConnectorEventListener; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.UI; import com.vaadin.util.ReflectTools; @@ -194,37 +192,6 @@ public interface ClientConnector extends Connector { */ public void markAsDirtyRecursive(); - /** - * Sets the parent connector of the connector. - * - *

      - * This method automatically calls {@link #attach()} if the connector - * becomes attached to the application, regardless of whether it was - * attached previously. Conversely, if the parent is {@code null} and the - * connector is attached to the application, {@link #detach()} is called for - * the connector. - *

      - *

      - * This method is rarely called directly. One of the - * {@link ComponentContainer#addComponent(Component)} or - * {@link AbstractClientConnector#addExtension(Extension)} methods are - * normally used for adding connectors to a parent and they will call this - * method implicitly. - *

      - * - *

      - * It is not possible to change the parent without first setting the parent - * to {@code null}. - *

      - * - * @param parent - * the parent connector - * @throws IllegalStateException - * if a parent is given even though the connector already has a - * parent - */ - public void setParent(ClientConnector parent); - /** * Checks if the connector is attached to a VaadinSession. * diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index df2361e887..cef1bb86e7 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -314,12 +314,6 @@ public class DragAndDropService implements VariableOwner, ClientConnector { } - @Override - public void setParent(ClientConnector parent) { - // TODO Auto-generated method stub - - } - @Override public void attach() { // TODO Auto-generated method stub diff --git a/server/src/com/vaadin/server/Extension.java b/server/src/com/vaadin/server/Extension.java index 2e632fc6c9..0f3d81598e 100644 --- a/server/src/com/vaadin/server/Extension.java +++ b/server/src/com/vaadin/server/Extension.java @@ -35,4 +35,25 @@ public interface Extension extends ClientConnector { * removed, it cannot be attached again. */ void remove(); + + /** + * Sets the parent connector of the connector. + * + * This method automatically calls {@link #attach()} if the connector + * becomes attached to the session. + *

      + * This method is rarely called directly. + * {@link AbstractClientConnector#addExtension(Extension)} is normally used + * for adding extensions to a parent and it will call this method + * implicitly. + *

      + * + * @param parent + * the parent connector + * @throws IllegalStateException + * if a parent is given even though the connector already has a + * parent + */ + public void setParent(ClientConnector parent); + } diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 9ff36a42d2..0bf27435fb 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import com.vaadin.event.ActionManager; import com.vaadin.event.ShortcutListener; import com.vaadin.server.AbstractClientConnector; -import com.vaadin.server.ClientConnector; import com.vaadin.server.ComponentSizeValidator; import com.vaadin.server.ErrorHandler; import com.vaadin.server.ErrorMessage; @@ -94,6 +93,8 @@ public abstract class AbstractComponent extends AbstractClientConnector private boolean visible = true; + private HasComponents parent; + /* Constructor */ /** @@ -451,17 +452,32 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public HasComponents getParent() { - return (HasComponents) super.getParent(); + return parent; } @Override - public void setParent(ClientConnector parent) { - if (parent == null || parent instanceof HasComponents) { - super.setParent(parent); - } else { - throw new IllegalArgumentException( - "The parent of a Component must implement HasComponents, which " - + parent.getClass() + " doesn't do."); + public void setParent(HasComponents parent) { + // If the parent is not changed, don't do anything + if (parent == this.parent) { + return; + } + + if (parent != null && this.parent != null) { + throw new IllegalStateException(getClass().getName() + + " already has a parent."); + } + + // Send a detach event if the component is currently attached + if (isAttached()) { + detach(); + } + + // Connect to new parent + this.parent = parent; + + // Send attach event if the component is now attached + if (isAttached()) { + attach(); } } diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index 20958812fc..485327bb54 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -332,6 +332,32 @@ public interface Component extends ClientConnector, Sizeable, Serializable { */ public void setVisible(boolean visible); + /** + * Sets the parent connector of the component. + * + *

      + * This method automatically calls {@link #attach()} if the component + * becomes attached to the session, regardless of whether it was attached + * previously. Conversely, if the component currently is attached to the + * session, {@link #detach()} is called for the connector before attaching + * it to a new parent. + *

      + *

      + * This method is rarely called directly. + * {@link ComponentContainer#addComponent(Component)} or a + * {@link HasComponents} specific method is normally used for adding + * components to a parent and the used method will call this method + * implicitly. + *

      + * + * @param parent + * the parent connector + * @throws IllegalStateException + * if a parent is given even though the connector already has a + * parent + */ + public void setParent(HasComponents parent); + /** * Gets the parent component of the component. * diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index 9f64c9118e..700d0eb387 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -31,7 +31,6 @@ import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; -import com.vaadin.server.ClientConnector; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.MouseEventDetails; @@ -139,7 +138,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * ) */ @Override - public void setParent(ClientConnector parent) { + public void setParent(HasComponents parent) { if (parent == null || parent instanceof UI) { super.setParent(parent); } else { -- cgit v1.2.3 From 5793a1c3a2da2c9771bd1721483a4689100d4bc3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 11 Jun 2013 13:21:09 +0300 Subject: Make VaadinServlet use enclosing UI class by default (#12039) Change-Id: Ica2b9b9d82ef6d683cb51f3478a07e57cbfa28e5 --- server/src/com/vaadin/server/VaadinServlet.java | 12 ++++++++++++ .../vaadin/server/VaadinServletConfigurationTest.java | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index a3030c9d8d..a9eb42578e 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -44,6 +44,7 @@ import com.vaadin.annotations.VaadinServletConfiguration.InitParameterName; import com.vaadin.sass.internal.ScssStylesheet; import com.vaadin.server.communication.ServletUIInitHandler; import com.vaadin.shared.JsonConstants; +import com.vaadin.ui.UI; import com.vaadin.util.CurrentInstance; @SuppressWarnings("serial") @@ -69,6 +70,8 @@ public class VaadinServlet extends HttpServlet implements Constants { super.init(servletConfig); Properties initParameters = new Properties(); + readUiFromEnclosingClass(initParameters); + readConfigurationAnnotation(initParameters); // Read default parameters from server.xml @@ -101,6 +104,15 @@ public class VaadinServlet extends HttpServlet implements Constants { CurrentInstance.clearAll(); } + private void readUiFromEnclosingClass(Properties initParameters) { + Class enclosingClass = getClass().getEnclosingClass(); + + if (enclosingClass != null && UI.class.isAssignableFrom(enclosingClass)) { + initParameters.put(VaadinSession.UI_PARAMETER, + enclosingClass.getName()); + } + } + private void readConfigurationAnnotation(Properties initParameters) throws ServletException { VaadinServletConfiguration configAnnotation = UIProvider diff --git a/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java b/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java index 80cb1d7b0c..d347534f5c 100644 --- a/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java +++ b/server/tests/src/com/vaadin/server/VaadinServletConfigurationTest.java @@ -32,16 +32,35 @@ import org.junit.Test; import com.vaadin.annotations.VaadinServletConfiguration; import com.vaadin.server.DeploymentConfiguration.LegacyProperyToStringMode; import com.vaadin.server.VaadinServletConfigurationTest.MockUI; +import com.vaadin.server.VaadinServletConfigurationTest.MockUI.ServletInUI; import com.vaadin.ui.UI; public class VaadinServletConfigurationTest { public static class MockUI extends UI { + + public static class ServletInUI extends VaadinServlet { + // This servlet should automatically be configured to use the + // enclosing UI class + } + @Override protected void init(VaadinRequest request) { // Do nothing } } + @Test + public void testEnclosingUIClass() throws Exception { + ServletInUI servlet = new MockUI.ServletInUI(); + servlet.init(new MockServletConfig()); + + Class uiClass = new DefaultUIProvider() + .getUIClass(new UIClassSelectionEvent(new VaadinServletRequest( + EasyMock.createMock(HttpServletRequest.class), servlet + .getService()))); + Assert.assertEquals(MockUI.class, uiClass); + } + @Test public void testValuesFromAnnotation() throws ServletException { TestServlet servlet = new TestServlet(); -- cgit v1.2.3 From 3d9d47d222a53e33267cb3f26112782fe9f12caf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2013 20:01:40 +0300 Subject: Added type parameter to converter methods (#11895) Change-Id: I6562c537d9e5a0745eb67bc613123a265578ae00 --- .../converter/AbstractStringToNumberConverter.java | 6 ++-- .../com/vaadin/data/util/converter/Converter.java | 37 ++++++++++++++-------- .../vaadin/data/util/converter/ConverterUtil.java | 24 ++++++++++++-- .../data/util/converter/DateToLongConverter.java | 15 ++++++--- .../util/converter/DateToSqlDateConverter.java | 17 ++++++++-- .../data/util/converter/ReverseConverter.java | 10 +++--- .../util/converter/StringToBooleanConverter.java | 10 +++--- .../data/util/converter/StringToDateConverter.java | 21 ++++++++---- .../util/converter/StringToDoubleConverter.java | 5 +-- .../util/converter/StringToFloatConverter.java | 5 +-- .../util/converter/StringToIntegerConverter.java | 11 ++++--- .../util/converter/StringToNumberConverter.java | 13 ++++++-- server/src/com/vaadin/ui/AbstractField.java | 28 +++++++++++----- server/src/com/vaadin/ui/Table.java | 3 +- .../tests/data/converter/ConverterFactory.java | 6 ++-- .../converter/TestAnyEnumToStringConverter.java | 37 ++++++++++------------ .../data/converter/TestDateToLongConverter.java | 4 +-- .../TestSpecificEnumToStringConverter.java | 16 ++++++---- .../converter/TestStringToBooleanConverter.java | 8 ++--- .../data/converter/TestStringToDateConverter.java | 6 ++-- .../converter/TestStringToDoubleConverter.java | 6 ++-- .../data/converter/TestStringToFloatConverter.java | 7 ++-- .../converter/TestStringToIntegerConverter.java | 7 ++-- .../converter/TestStringToNumberConverter.java | 9 +++--- .../abstractfield/AbsFieldValueConversions.java | 14 +++++--- .../Vaadin6ImplicitDoubleConverter.java | 6 ++-- .../tests/components/table/DoublesInTable.java | 24 +++++++++----- .../table/TableWithCustomConverterFactory.java | 6 ++-- .../converter/ConverterThatEnforcesAFormat.java | 3 +- .../minitutorials/v7a1/StringMyTypeConverter.java | 7 ++-- 30 files changed, 241 insertions(+), 130 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java b/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java index 5999d850b4..237f01bb22 100644 --- a/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java +++ b/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java @@ -65,7 +65,8 @@ public abstract class AbstractStringToNumberConverter implements * If there was a problem converting the value * @since 7.1 */ - protected Number convertToNumber(String value, Locale locale) + protected Number convertToNumber(String value, + Class targetType, Locale locale) throws ConversionException { if (value == null) { return null; @@ -98,7 +99,8 @@ public abstract class AbstractStringToNumberConverter implements * .Object, java.util.Locale) */ @Override - public String convertToPresentation(T value, Locale locale) + public String convertToPresentation(T value, + Class targetType, Locale locale) throws ConversionException { if (value == null) { return null; diff --git a/server/src/com/vaadin/data/util/converter/Converter.java b/server/src/com/vaadin/data/util/converter/Converter.java index ded7da7fb5..3c391af434 100644 --- a/server/src/com/vaadin/data/util/converter/Converter.java +++ b/server/src/com/vaadin/data/util/converter/Converter.java @@ -22,10 +22,10 @@ import java.util.Locale; /** * Interface that implements conversion between a model and a presentation type. *

      - * Typically {@link #convertToPresentation(Object, Locale)} and - * {@link #convertToModel(Object, Locale)} should be symmetric so that chaining - * these together returns the original result for all input but this is not a - * requirement. + * Typically {@link #convertToPresentation(Object, Class, Locale)} and + * {@link #convertToModel(Object, Class, Locale)} should be symmetric so that + * chaining these together returns the original result for all input but this is + * not a requirement. *

      *

      * Converters must not have any side effects (never update UI from inside a @@ -55,19 +55,23 @@ public interface Converter extends Serializable { * A converter can optionally use locale to do the conversion. *

      * A converter should in most cases be symmetric so chaining - * {@link #convertToPresentation(Object, Locale)} and - * {@link #convertToModel(Object, Locale)} should return the original value. + * {@link #convertToPresentation(Object, Class, Locale)} and + * {@link #convertToModel(Object, Class, Locale)} should return the original + * value. * * @param value * The value to convert, compatible with the target type. Can be * null + * @param targetType + * The requested type of the return value * @param locale * The locale to use for conversion. Can be null. * @return The converted value compatible with the source type * @throws ConversionException * If the value could not be converted */ - public MODEL convertToModel(PRESENTATION value, Locale locale) + public MODEL convertToModel(PRESENTATION value, + Class targetType, Locale locale) throws ConversionException; /** @@ -76,26 +80,30 @@ public interface Converter extends Serializable { * A converter can optionally use locale to do the conversion. *

      * A converter should in most cases be symmetric so chaining - * {@link #convertToPresentation(Object, Locale)} and - * {@link #convertToModel(Object, Locale)} should return the original value. + * {@link #convertToPresentation(Object, Class, Locale)} and + * {@link #convertToModel(Object, Class, Locale)} should return the original + * value. * * @param value * The value to convert, compatible with the target type. Can be * null + * @param targetType + * The requested type of the return value * @param locale * The locale to use for conversion. Can be null. * @return The converted value compatible with the source type * @throws ConversionException * If the value could not be converted */ - public PRESENTATION convertToPresentation(MODEL value, Locale locale) + public PRESENTATION convertToPresentation(MODEL value, + Class targetType, Locale locale) throws ConversionException; /** * The source type of the converter. * * Values of this type can be passed to - * {@link #convertToPresentation(Object, Locale)}. + * {@link #convertToPresentation(Object, Class, Locale)}. * * @return The source type */ @@ -105,7 +113,7 @@ public interface Converter extends Serializable { * The target type of the converter. * * Values of this type can be passed to - * {@link #convertToModel(Object, Locale)}. + * {@link #convertToModel(Object, Class, Locale)}. * * @return The target type */ @@ -113,8 +121,9 @@ public interface Converter extends Serializable { /** * An exception that signals that the value passed to - * {@link Converter#convertToPresentation(Object, Locale)} or - * {@link Converter#convertToModel(Object, Locale)} could not be converted. + * {@link Converter#convertToPresentation(Object, Class, Locale)} or + * {@link Converter#convertToModel(Object, Class, Locale)} could not be + * converted. * * @author Vaadin Ltd * @since 7.0 diff --git a/server/src/com/vaadin/data/util/converter/ConverterUtil.java b/server/src/com/vaadin/data/util/converter/ConverterUtil.java index 08d7363084..3c62a71b73 100644 --- a/server/src/com/vaadin/data/util/converter/ConverterUtil.java +++ b/server/src/com/vaadin/data/util/converter/ConverterUtil.java @@ -86,7 +86,17 @@ public class ConverterUtil implements Serializable { Converter converter, Locale locale) throws Converter.ConversionException { if (converter != null) { - return converter.convertToPresentation(modelValue, locale); + PRESENTATIONTYPE presentation = converter.convertToPresentation( + modelValue, presentationType, locale); + if (!presentationType.isInstance(presentation)) { + throw new Converter.ConversionException( + "Converter returned an object of type " + + presentation.getClass().getName() + + " when expecting " + + presentationType.getName()); + } + + return presentation; } if (modelValue == null) { return null; @@ -123,7 +133,17 @@ public class ConverterUtil implements Serializable { * If there is a converter, always use it. It must convert or throw * an exception. */ - return converter.convertToModel(presentationValue, locale); + MODELTYPE model = converter.convertToModel(presentationValue, + modelType, locale); + if (!modelType.isInstance(model)) { + throw new Converter.ConversionException( + "Converter returned an object of type " + + model.getClass().getName() + + " when expecting " + modelType.getName()); + } + + return model; + } if (presentationValue == null) { diff --git a/server/src/com/vaadin/data/util/converter/DateToLongConverter.java b/server/src/com/vaadin/data/util/converter/DateToLongConverter.java index 82dccdcacc..6aedc74f6d 100644 --- a/server/src/com/vaadin/data/util/converter/DateToLongConverter.java +++ b/server/src/com/vaadin/data/util/converter/DateToLongConverter.java @@ -32,10 +32,11 @@ public class DateToLongConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, - * java.util.Locale) + * java.lang.Class, java.util.Locale) */ @Override - public Long convertToModel(Date value, Locale locale) { + public Long convertToModel(Date value, Class targetType, + Locale locale) { if (value == null) { return null; } @@ -48,10 +49,16 @@ public class DateToLongConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang - * .Object, java.util.Locale) + * .Object, java.lang.Class, java.util.Locale) */ @Override - public Date convertToPresentation(Long value, Locale locale) { + public Date convertToPresentation(Long value, + Class targetType, Locale locale) { + if (targetType != getPresentationType()) { + throw new ConversionException("Converter only supports " + + getPresentationType().getName() + " (targetType was " + + targetType.getName() + ")"); + } if (value == null) { return null; } diff --git a/server/src/com/vaadin/data/util/converter/DateToSqlDateConverter.java b/server/src/com/vaadin/data/util/converter/DateToSqlDateConverter.java index 97027cc05b..cddf2d8a42 100644 --- a/server/src/com/vaadin/data/util/converter/DateToSqlDateConverter.java +++ b/server/src/com/vaadin/data/util/converter/DateToSqlDateConverter.java @@ -35,14 +35,27 @@ import java.util.Locale; public class DateToSqlDateConverter implements Converter { @Override - public java.sql.Date convertToModel(Date value, Locale locale) + public java.sql.Date convertToModel(Date value, + Class targetType, Locale locale) throws ConversionException { + if (targetType != getModelType()) { + throw new ConversionException("Converter only supports " + + getModelType().getName() + " (targetType was " + + targetType.getName() + ")"); + } + return new java.sql.Date(value.getTime()); } @Override - public Date convertToPresentation(java.sql.Date value, Locale locale) + public Date convertToPresentation(java.sql.Date value, + Class targetType, Locale locale) throws ConversionException { + if (targetType != getPresentationType()) { + throw new ConversionException("Converter only supports " + + getPresentationType().getName() + " (targetType was " + + targetType.getName() + ")"); + } return new Date(value.getTime()); } diff --git a/server/src/com/vaadin/data/util/converter/ReverseConverter.java b/server/src/com/vaadin/data/util/converter/ReverseConverter.java index 94f333b7f3..6fa07696db 100644 --- a/server/src/com/vaadin/data/util/converter/ReverseConverter.java +++ b/server/src/com/vaadin/data/util/converter/ReverseConverter.java @@ -53,9 +53,10 @@ public class ReverseConverter implements * .lang.Object, java.util.Locale) */ @Override - public MODEL convertToModel(PRESENTATION value, Locale locale) + public MODEL convertToModel(PRESENTATION value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return realConverter.convertToPresentation(value, locale); + return realConverter.convertToPresentation(value, targetType, locale); } /* @@ -66,9 +67,10 @@ public class ReverseConverter implements * .Object, java.util.Locale) */ @Override - public PRESENTATION convertToPresentation(MODEL value, Locale locale) + public PRESENTATION convertToPresentation(MODEL value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return realConverter.convertToModel(value, locale); + return realConverter.convertToModel(value, targetType, locale); } /* diff --git a/server/src/com/vaadin/data/util/converter/StringToBooleanConverter.java b/server/src/com/vaadin/data/util/converter/StringToBooleanConverter.java index 1702d3808f..6af0933731 100644 --- a/server/src/com/vaadin/data/util/converter/StringToBooleanConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToBooleanConverter.java @@ -35,10 +35,11 @@ public class StringToBooleanConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, - * java.util.Locale) + * java.lang.Class, java.util.Locale) */ @Override - public Boolean convertToModel(String value, Locale locale) + public Boolean convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { if (value == null || value.isEmpty()) { return null; @@ -80,10 +81,11 @@ public class StringToBooleanConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang - * .Object, java.util.Locale) + * .Object, java.lang.Class, java.util.Locale) */ @Override - public String convertToPresentation(Boolean value, Locale locale) + public String convertToPresentation(Boolean value, + Class targetType, Locale locale) throws ConversionException { if (value == null) { return null; diff --git a/server/src/com/vaadin/data/util/converter/StringToDateConverter.java b/server/src/com/vaadin/data/util/converter/StringToDateConverter.java index 0dcf1d4795..e3917c6a52 100644 --- a/server/src/com/vaadin/data/util/converter/StringToDateConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToDateConverter.java @@ -37,8 +37,9 @@ import java.util.Locale; public class StringToDateConverter implements Converter { /** - * Returns the format used by {@link #convertToPresentation(Date, Locale)} - * and {@link #convertToModel(String, Locale)}. + * Returns the format used by + * {@link #convertToPresentation(Date, Class,Locale)} and + * {@link #convertToModel(String, Class, Locale)}. * * @param locale * The locale to use @@ -60,11 +61,18 @@ public class StringToDateConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, - * java.util.Locale) + * java.lang.Class, java.util.Locale) */ @Override - public Date convertToModel(String value, Locale locale) + public Date convertToModel(String value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + if (targetType != getModelType()) { + throw new ConversionException("Converter only supports " + + getModelType().getName() + " (targetType was " + + targetType.getName() + ")"); + } + if (value == null) { return null; } @@ -87,10 +95,11 @@ public class StringToDateConverter implements Converter { * * @see * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang - * .Object, java.util.Locale) + * .Object, java.lang.Class, java.util.Locale) */ @Override - public String convertToPresentation(Date value, Locale locale) + public String convertToPresentation(Date value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; diff --git a/server/src/com/vaadin/data/util/converter/StringToDoubleConverter.java b/server/src/com/vaadin/data/util/converter/StringToDoubleConverter.java index 8bb82498b9..c593d256da 100644 --- a/server/src/com/vaadin/data/util/converter/StringToDoubleConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToDoubleConverter.java @@ -44,9 +44,10 @@ public class StringToDoubleConverter extends * java.util.Locale) */ @Override - public Double convertToModel(String value, Locale locale) + public Double convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { - Number n = convertToNumber(value, locale); + Number n = convertToNumber(value, targetType, locale); return n == null ? null : n.doubleValue(); } diff --git a/server/src/com/vaadin/data/util/converter/StringToFloatConverter.java b/server/src/com/vaadin/data/util/converter/StringToFloatConverter.java index a207654358..6fcb83a770 100644 --- a/server/src/com/vaadin/data/util/converter/StringToFloatConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToFloatConverter.java @@ -44,9 +44,10 @@ public class StringToFloatConverter extends * java.util.Locale) */ @Override - public Float convertToModel(String value, Locale locale) + public Float convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { - Number n = convertToNumber(value, locale); + Number n = convertToNumber(value, targetType, locale); return n == null ? null : n.floatValue(); } diff --git a/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java b/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java index 4f34cf1cd3..bc436112fe 100644 --- a/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java @@ -35,8 +35,8 @@ public class StringToIntegerConverter extends /** * Returns the format used by - * {@link #convertToPresentation(Integer, Locale)} and - * {@link #convertToModel(String, Locale)}. + * {@link #convertToPresentation(Integer, Class, Locale)} and + * {@link #convertToModel(String, Class, Locale)} * * @param locale * The locale to use @@ -55,12 +55,13 @@ public class StringToIntegerConverter extends * * @see * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, - * java.util.Locale) + * java.lang.Class, java.util.Locale) */ @Override - public Integer convertToModel(String value, Locale locale) + public Integer convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { - Number n = convertToNumber(value, locale); + Number n = convertToNumber(value, targetType, locale); return n == null ? null : n.intValue(); } diff --git a/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java b/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java index eae73e4cfa..22df42403f 100644 --- a/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java @@ -37,12 +37,19 @@ public class StringToNumberConverter extends * * @see * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, - * java.util.Locale) + * java.lang.Class, java.util.Locale) */ @Override - public Number convertToModel(String value, Locale locale) + public Number convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { - return convertToNumber(value, locale); + if (targetType != getModelType()) { + throw new ConversionException("Converter only supports " + + getModelType().getName() + " (targetType was " + + targetType.getName() + ")"); + } + + return convertToNumber(value, targetType, locale); } /* diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 7ac3a57c46..6a52d6b849 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -740,13 +740,7 @@ public abstract class AbstractField extends AbstractComponent implements */ private Object convertToModel(T fieldValue, Locale locale) throws Converter.ConversionException { - Class modelType = null; - Property pd = getPropertyDataSource(); - if (pd != null) { - modelType = pd.getType(); - } else if (getConverter() != null) { - modelType = getConverter().getModelType(); - } + Class modelType = getModelType(); try { return ConverterUtil.convertToModel(fieldValue, (Class) modelType, getConverter(), locale); @@ -755,6 +749,24 @@ public abstract class AbstractField extends AbstractComponent implements } } + /** + * Retrieves the type of the currently used data model. If the field has no + * data source then the model type of the converter is used. + * + * @since 7.1 + * @return The type of the currently used data model or null if no data + * source or converter is set. + */ + protected Class getModelType() { + Property pd = getPropertyDataSource(); + if (pd != null) { + return pd.getType(); + } else if (getConverter() != null) { + return getConverter().getModelType(); + } + return null; + } + /** * Returns the conversion error with {0} replaced by the data source type * and {1} replaced by the exception (localized) message. @@ -935,7 +947,7 @@ public abstract class AbstractField extends AbstractComponent implements if (getConverter() != null) { try { valueToValidate = getConverter().convertToModel(fieldValue, - getLocale()); + getModelType(), getLocale()); } catch (ConversionException e) { throw new InvalidValueException(getConversionError( getConverter().getModelType(), e)); diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 3d7cb42050..a688b2eb45 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -4011,7 +4011,8 @@ public class Table extends AbstractSelect implements Action.Container, } Object value = property.getValue(); if (converter != null) { - return converter.convertToPresentation(value, getLocale()); + return converter.convertToPresentation(value, String.class, + getLocale()); } return (null != value) ? value.toString() : ""; } diff --git a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java index 9da8406507..b53c5a930f 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java @@ -30,13 +30,15 @@ public class ConverterFactory extends TestCase { public static class ConvertTo42 implements Converter { @Override - public Integer convertToModel(String value, Locale locale) + public Integer convertToModel(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return 42; } @Override - public String convertToPresentation(Integer value, Locale locale) + public String convertToPresentation(Integer value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return "42"; } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java index c267e012e8..e21382069f 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java @@ -33,14 +33,12 @@ public class TestAnyEnumToStringConverter { public class AnyEnumToStringConverter implements Converter { - private Class[] enumClass; - - public AnyEnumToStringConverter(Class... enumClass) { - this.enumClass = enumClass; + public AnyEnumToStringConverter() { } @Override - public String convertToModel(Enum value, Locale locale) + public String convertToModel(Enum value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; @@ -50,16 +48,15 @@ public class TestAnyEnumToStringConverter { } @Override - public Enum convertToPresentation(String value, Locale locale) + public Enum convertToPresentation(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; } - for (Class candidate : enumClass) { - for (Enum e : candidate.getEnumConstants()) { - if (e.toString().equals(value)) { - return e; - } + for (Enum e : targetType.getEnumConstants()) { + if (e.toString().equals(value)) { + return e; } } @@ -82,29 +79,29 @@ public class TestAnyEnumToStringConverter { @Before public void setup() { - converter = new AnyEnumToStringConverter(TestEnum.class, - AnotherTestEnum.class); + converter = new AnyEnumToStringConverter(); } @Test public void nullConversion() { - Assert.assertEquals(null, converter.convertToModel(null, null)); + Assert.assertEquals(null, converter.convertToModel(null, null, null)); } @Test public void enumToStringConversion() { Assert.assertEquals(TestEnum.TWO.toString(), - converter.convertToModel(TestEnum.TWO, null)); - Assert.assertEquals(AnotherTestEnum.TWO.toString(), - converter.convertToModel(AnotherTestEnum.TWO, null)); + converter.convertToModel(TestEnum.TWO, String.class, null)); + Assert.assertEquals(AnotherTestEnum.TWO.toString(), converter + .convertToModel(AnotherTestEnum.TWO, String.class, null)); } @Test public void stringToEnumConversion() { - Assert.assertEquals(TestEnum.TWO, - converter.convertToPresentation(TestEnum.TWO.toString(), null)); + Assert.assertEquals(TestEnum.TWO, converter.convertToPresentation( + TestEnum.TWO.toString(), TestEnum.class, null)); Assert.assertEquals(AnotherTestEnum.TWO, converter - .convertToPresentation(AnotherTestEnum.TWO.toString(), null)); + .convertToPresentation(AnotherTestEnum.TWO.toString(), + AnotherTestEnum.class, null)); } @Test diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java index aab4ae18f0..6b9fa93e27 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java @@ -11,11 +11,11 @@ public class TestDateToLongConverter extends TestCase { DateToLongConverter converter = new DateToLongConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, Long.class, null)); } public void testValueConversion() { assertEquals(Long.valueOf(946677600000l), - converter.convertToModel(new Date(100, 0, 1), null)); + converter.convertToModel(new Date(100, 0, 1), Long.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java index 93dbe96b56..8ce7b8eab8 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java @@ -41,7 +41,8 @@ public class TestSpecificEnumToStringConverter { } @Override - public String convertToModel(Enum value, Locale locale) + public String convertToModel(Enum value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; @@ -51,7 +52,8 @@ public class TestSpecificEnumToStringConverter { } @Override - public Enum convertToPresentation(String value, Locale locale) + public Enum convertToPresentation(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; @@ -90,19 +92,21 @@ public class TestSpecificEnumToStringConverter { @Test public void nullConversion() { - Assert.assertEquals(null, testEnumConverter.convertToModel(null, null)); + Assert.assertEquals(null, + testEnumConverter.convertToModel(null, null, null)); } @Test public void enumToStringConversion() { - Assert.assertEquals(TestEnum.TWO.toString(), - testEnumConverter.convertToModel(TestEnum.TWO, null)); + Assert.assertEquals(TestEnum.TWO.toString(), testEnumConverter + .convertToModel(TestEnum.TWO, String.class, null)); } @Test public void stringToEnumConversion() { Assert.assertEquals(TestEnum.TWO, testEnumConverter - .convertToPresentation(TestEnum.TWO.toString(), null)); + .convertToPresentation(TestEnum.TWO.toString(), TestEnum.class, + null)); } @Test diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java index 1c2b919db0..f236bb4000 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java @@ -9,15 +9,15 @@ public class TestStringToBooleanConverter extends TestCase { StringToBooleanConverter converter = new StringToBooleanConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Boolean.class, null)); } public void testValueConversion() { - assertTrue(converter.convertToModel("true", null)); - assertFalse(converter.convertToModel("false", null)); + assertTrue(converter.convertToModel("true", Boolean.class, null)); + assertFalse(converter.convertToModel("false", Boolean.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java index 2961b93c89..59314bd5ee 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java @@ -12,15 +12,15 @@ public class TestStringToDateConverter extends TestCase { StringToDateConverter converter = new StringToDateConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Date.class, null)); } public void testValueConversion() { assertEquals(new Date(100, 0, 1), converter.convertToModel( - "Jan 1, 2000 12:00:00 AM", Locale.ENGLISH)); + "Jan 1, 2000 12:00:00 AM", Date.class, Locale.ENGLISH)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java index 9903a8deaa..739f9b7d5a 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java @@ -9,14 +9,14 @@ public class TestStringToDoubleConverter extends TestCase { StringToDoubleConverter converter = new StringToDoubleConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Double.class, null)); } public void testValueConversion() { - assertEquals(10.0, converter.convertToModel("10", null)); + assertEquals(10.0, converter.convertToModel("10", Double.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java index 670daec202..3bb2b3649e 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java @@ -9,14 +9,15 @@ public class TestStringToFloatConverter extends TestCase { StringToFloatConverter converter = new StringToFloatConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Float.class, null)); } public void testValueConversion() { - assertEquals(Float.valueOf(10), converter.convertToModel("10", null)); + assertEquals(Float.valueOf(10), + converter.convertToModel("10", Float.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java index 80414cccaf..7f247b791f 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java @@ -9,14 +9,15 @@ public class TestStringToIntegerConverter extends TestCase { StringToIntegerConverter converter = new StringToIntegerConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Integer.class, null)); } public void testValueConversion() { - assertEquals(Integer.valueOf(10), converter.convertToModel("10", null)); + assertEquals(Integer.valueOf(10), + converter.convertToModel("10", Integer.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java index d3f87d628a..9c322cd301 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java @@ -9,15 +9,16 @@ public class TestStringToNumberConverter extends TestCase { StringToNumberConverter converter = new StringToNumberConverter(); public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, null)); + assertEquals(null, converter.convertToModel(null, null, null)); } public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", null)); + assertEquals(null, converter.convertToModel("", Number.class, null)); } public void testValueConversion() { - assertEquals(Long.valueOf(10), converter.convertToModel("10", null)); - assertEquals(10.5, converter.convertToModel("10.5", null)); + assertEquals(Long.valueOf(10), + converter.convertToModel("10", Number.class, null)); + assertEquals(10.5, converter.convertToModel("10.5", Number.class, null)); } } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java index b5e937f27d..9854296538 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java @@ -85,12 +85,14 @@ public class AbsFieldValueConversions extends TestCase { tf.setConverter(new Converter() { @Override - public String convertToModel(String value, Locale locale) { + public String convertToModel(String value, + Class targetType, Locale locale) { return value; } @Override - public String convertToPresentation(String value, Locale locale) { + public String convertToPresentation(String value, + Class targetType, Locale locale) { return value; } @@ -150,7 +152,8 @@ public class AbsFieldValueConversions extends TestCase { cb.setConverter(new Converter() { @Override - public Boolean convertToModel(Boolean value, Locale locale) { + public Boolean convertToModel(Boolean value, + Class targetType, Locale locale) { // value from a CheckBox should never be null as long as it is // not set to null (handled by conversion below). assertNotNull(value); @@ -158,7 +161,8 @@ public class AbsFieldValueConversions extends TestCase { } @Override - public Boolean convertToPresentation(Boolean value, Locale locale) { + public Boolean convertToPresentation(Boolean value, + Class targetType, Locale locale) { // Datamodel -> field if (value == null) { return false; @@ -184,7 +188,7 @@ public class AbsFieldValueConversions extends TestCase { assertEquals(Boolean.FALSE, property.getValue()); assertEquals(Boolean.FALSE, cb.getValue()); Boolean newDmValue = cb.getConverter().convertToPresentation( - cb.getValue(), new Locale("fi", "FI")); + cb.getValue(), Boolean.class, new Locale("fi", "FI")); assertEquals(Boolean.FALSE, newDmValue); // FIXME: Should be able to set to false here to cause datamodel to be diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/Vaadin6ImplicitDoubleConverter.java b/uitest/src/com/vaadin/tests/components/abstractfield/Vaadin6ImplicitDoubleConverter.java index a9aa4d2a43..33359cc2c6 100644 --- a/uitest/src/com/vaadin/tests/components/abstractfield/Vaadin6ImplicitDoubleConverter.java +++ b/uitest/src/com/vaadin/tests/components/abstractfield/Vaadin6ImplicitDoubleConverter.java @@ -8,7 +8,8 @@ public class Vaadin6ImplicitDoubleConverter implements Converter { @Override - public Double convertToModel(String value, Locale locale) + public Double convertToModel(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (null == value) { return null; @@ -17,7 +18,8 @@ public class Vaadin6ImplicitDoubleConverter implements } @Override - public String convertToPresentation(Double value, Locale locale) + public String convertToPresentation(Double value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; diff --git a/uitest/src/com/vaadin/tests/components/table/DoublesInTable.java b/uitest/src/com/vaadin/tests/components/table/DoublesInTable.java index 920ccc2038..355cd43d37 100644 --- a/uitest/src/com/vaadin/tests/components/table/DoublesInTable.java +++ b/uitest/src/com/vaadin/tests/components/table/DoublesInTable.java @@ -150,14 +150,16 @@ public class DoublesInTable extends TestBase { t.setConverter("sex", new Converter() { @Override - public Sex convertToModel(String value, Locale locale) + public Sex convertToModel(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { // not used in this test - Table only converts to presentation return null; } @Override - public String convertToPresentation(Sex value, Locale locale) + public String convertToPresentation(Sex value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { value = Sex.UNKNOWN; @@ -178,14 +180,16 @@ public class DoublesInTable extends TestBase { t.setConverter("deceased", new Converter() { @Override - public Boolean convertToModel(String value, Locale locale) { + public Boolean convertToModel(String value, + Class targetType, Locale locale) { // not used in this test - Table only converts from source to // target return null; } @Override - public String convertToPresentation(Boolean value, Locale locale) { + public String convertToPresentation(Boolean value, + Class targetType, Locale locale) { if (value == null || value) { return "YES, DEAD!"; } else { @@ -206,7 +210,8 @@ public class DoublesInTable extends TestBase { t.setConverter("age", new Converter() { @Override - public Integer convertToModel(String value, Locale locale) + public Integer convertToModel(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { // not used in this test - Table only converts from source to // target @@ -214,7 +219,8 @@ public class DoublesInTable extends TestBase { } @Override - public String convertToPresentation(Integer value, Locale locale) + public String convertToPresentation(Integer value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; @@ -243,14 +249,16 @@ public class DoublesInTable extends TestBase { t.setConverter("address", new Converter() { @Override - public Address convertToModel(String value, Locale locale) + public Address convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { // not used in this test - Table only converts to presentation return null; } @Override - public String convertToPresentation(Address value, Locale locale) + public String convertToPresentation(Address value, + Class targetType, Locale locale) throws ConversionException { return value.getStreetAddress() + ", " + value.getCity() + " (" + value.getCountry() + ")"; diff --git a/uitest/src/com/vaadin/tests/components/table/TableWithCustomConverterFactory.java b/uitest/src/com/vaadin/tests/components/table/TableWithCustomConverterFactory.java index 60be786e8b..a3f0ce2f13 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableWithCustomConverterFactory.java +++ b/uitest/src/com/vaadin/tests/components/table/TableWithCustomConverterFactory.java @@ -29,14 +29,16 @@ public class TableWithCustomConverterFactory extends AbstractTestUI { Converter { @Override - public Integer convertToModel(String value, Locale locale) + public Integer convertToModel(String value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { // TODO Auto-generated method stub return null; } @Override - public String convertToPresentation(Integer value, Locale locale) + public String convertToPresentation(Integer value, + Class targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return "Integer: " + value; } diff --git a/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java index 6158092591..a37aa521ba 100644 --- a/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java +++ b/uitest/src/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java @@ -28,7 +28,8 @@ public class ConverterThatEnforcesAFormat extends TestBase { + "). Two-way conversion gives: " + tf.getConverter().convertToPresentation( tf.getConverter().convertToModel(tf.getValue(), - tf.getLocale()), tf.getLocale()) + ")"); + Double.class, tf.getLocale()), + String.class, tf.getLocale()) + ")"); } }); tf.setImmediate(true); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java index 9ec7a82580..8197cd82ae 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java @@ -52,8 +52,8 @@ public class StringMyTypeConverter extends AbstractTestUI { class StringToNameConverter implements Converter { @Override - public Name convertToModel(String text, Locale locale) - throws ConversionException { + public Name convertToModel(String text, Class targetType, + Locale locale) throws ConversionException { if (text == null) { return null; } @@ -66,7 +66,8 @@ class StringToNameConverter implements Converter { } @Override - public String convertToPresentation(Name name, Locale locale) + public String convertToPresentation(Name name, + Class targetType, Locale locale) throws ConversionException { if (name == null) { return null; -- cgit v1.2.3 From ecc2de3ff1b9998c8a7ca496e71a13c53acd5c84 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 7 Jun 2013 14:15:44 +0300 Subject: Removed dead code Change-Id: Iad8cc7a59389e2816088d542a7ca53a4b8cec72e --- server/src/com/vaadin/server/communication/UidlRequestHandler.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'server/src/com/vaadin') diff --git a/server/src/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/com/vaadin/server/communication/UidlRequestHandler.java index 3564aa65b5..d52c5e9fe0 100644 --- a/server/src/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/com/vaadin/server/communication/UidlRequestHandler.java @@ -75,7 +75,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements } checkWidgetsetVersion(request); - String requestThemeName = request.getParameter("theme"); // repaint requested or session has timed out and new one is created boolean repaintAll; @@ -114,7 +113,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements return true; } finally { stringWriter.close(); - requestThemeName = null; } return UIInitHandler.commitJsonResponse(request, response, -- cgit v1.2.3