diff options
Diffstat (limited to 'src/com/vaadin/ui/AbstractComponent.java')
-rw-r--r-- | src/com/vaadin/ui/AbstractComponent.java | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 189142519d..8c26911a9a 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -18,6 +18,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -879,18 +881,34 @@ public abstract class AbstractComponent implements Component, MethodEventSource /** * Creates the shared state bean to be used in server to client * communication. - * - * Subclasses should implement this method and return a new instance of the - * correct state class. - * - * All configuration of the values of the state should be performed in - * {@link #getState()}, not in {@link #createState()}. + * <p> + * By default a state object of the defined return type of + * {@link #getState()} is created. Subclasses can override this method and + * return a new instance of the correct state class but this should rarely + * be necessary. + * </p> + * <p> + * No configuration of the values of the state should be performed in + * {@link #createState()}. * * @since 7.0 * * @return new shared state object */ protected ComponentState createState() { + try { + Method m = getClass().getMethod("getState", (Class[]) null); + Class<? extends ComponentState> type = (Class<? extends ComponentState>) m + .getReturnType(); + return type.newInstance(); + } catch (Exception e) { + getLogger().log( + Level.INFO, + "Error determining state object class for " + + getClass().getName()); + } + + // Fall back to ComponentState if detection fails for some reason. return new ComponentState(); } @@ -1743,4 +1761,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource } return connectorId; } + + private Logger getLogger() { + return Logger.getLogger(AbstractComponent.class.getName()); + } } |