com.vaadin.addon.jpacontainer.fieldfactory
Class JPAContainerCustomField<T>

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.CustomComponent
              extended by com.vaadin.addon.jpacontainer.fieldfactory.JPAContainerCustomField<T>
All Implemented Interfaces:
com.vaadin.data.Buffered, com.vaadin.data.BufferedValidatable, com.vaadin.data.Property<T>, com.vaadin.data.Property.Editor, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer, com.vaadin.data.Validatable, com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Sizeable, com.vaadin.shared.Connector, com.vaadin.ui.Component, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Field<T>, com.vaadin.ui.HasComponents, Serializable, Iterable<com.vaadin.ui.Component>

public abstract class JPAContainerCustomField<T>
extends com.vaadin.ui.CustomComponent
implements com.vaadin.ui.Field<T>

A CustomComponent that implements the Field interface, enabling the creation of e.g. form fields by composing Vaadin components. Customization of both the visual presentation and the logic of the field is possible. Subclasses must at least implement the method getType() and set the composition root (typically in the constructor). In addition, other methods can be overridden to customize the functionality. Most custom fields can simply compose a user interface that calls the methods setValue(Object) and getValue(). It is also possible to override commit(), setPropertyDataSource(Property) and other logic of the field. Copied from the CustomField add-on.

Author:
Matti Tahvonen, Henri Sara
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Field
com.vaadin.ui.Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
com.vaadin.data.Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyException, com.vaadin.data.Property.ReadOnlyStatusChangeEvent, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.Transactional<T>, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
com.vaadin.server.Sizeable.Unit
 
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier, com.vaadin.ui.HasComponents.ComponentAttachEvent, com.vaadin.ui.HasComponents.ComponentAttachListener, com.vaadin.ui.HasComponents.ComponentDetachEvent, com.vaadin.ui.HasComponents.ComponentDetachListener
 
Field Summary
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
JPAContainerCustomField()
           
 
Method Summary
 void addListener(com.vaadin.data.Property.ValueChangeListener listener)
          Deprecated. 
 void addValidator(com.vaadin.data.Validator validator)
           
 void addValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void commit()
           
 void discard()
           
protected  void fireValueChange(boolean repaintIsNotNeeded)
          Emits the value change event.
 void focus()
           
 com.vaadin.server.ErrorMessage getErrorMessage()
          Error messages shown by the fields are composites of the error message thrown by the superclasses (that is the component error message), validation errors and buffered source errors.
 com.vaadin.data.Property<T> getPropertyDataSource()
           
 String getRequiredError()
           
 int getTabIndex()
           
abstract  Class<T> getType()
           
 Collection<com.vaadin.data.Validator> getValidators()
          Gets the validators of the field.
 T getValue()
          Gets the current value of the field.
protected  boolean isEmpty()
          Is the field empty? In general, "empty" state is same as null..
 boolean isInvalidAllowed()
          Fields allow invalid values by default.
 boolean isInvalidCommitted()
           
 boolean isModified()
           
 boolean isReadOnly()
           
 boolean isReadThrough()
           
 boolean isRequired()
          Is this field required.
 boolean isValid()
          Tests the current value against all registered validators.
 boolean isValidationVisible()
          Is automatic, visible validation enabled? If automatic validation is enabled, any validators connected to this component are evaluated while painting the component and potential error messages are sent to client.
 boolean isWriteThrough()
           
 void removeListener(com.vaadin.data.Property.ValueChangeListener listener)
          Deprecated. 
 void removeValidator(com.vaadin.data.Validator validator)
          Removes the validator from the field.
 void removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void setCurrentBufferedSourceException(com.vaadin.data.Buffered.SourceException currentBufferedSourceException)
           
protected  void setInternalValue(T newValue)
          Sets the internal field value.
 void setInvalidAllowed(boolean invalidAllowed)
          Fields allow invalid values by default.
 void setInvalidCommitted(boolean isCommitted)
           
 void setPropertyDataSource(com.vaadin.data.Property newDataSource)
           Sets the specified Property as the data source for the field.
 void setReadThrough(boolean readTrough)
           
 void setRequired(boolean required)
          Sets the field required.
 void setRequiredError(String requiredMessage)
          Set the error that is show if this field is required, but empty.
 void setTabIndex(int tabIndex)
           
 void setValidationVisible(boolean validateAutomatically)
          Enable or disable automatic, visible validation.
 void setValue(Object newValue)
           
protected  void setValue(Object newValue, boolean repaintIsNotNeeded)
          Sets the value of the field.
 void setWriteThrough(boolean writeTrough)
           
 String toString()
          Returns the value of the Property in human readable textual format.
 void validate()
          Checks the validity of the Validatable by validating the field with all attached validators.
 void valueChange(com.vaadin.data.Property.ValueChangeEvent event)
          This method listens to data source value changes and passes the changes forwards.
 
Methods inherited from class com.vaadin.ui.CustomComponent
getComponentCount, getCompositionRoot, iterator, setCompositionRoot
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getState, getState, getStyleName, getWidth, getWidthUnits, isConnectorEnabled, isEnabled, isImmediate, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hasListeners, isAttached, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Buffered
isBuffered, setBuffered
 
Methods inherited from interface com.vaadin.data.Validatable
removeAllValidators
 
Methods inherited from interface com.vaadin.data.Property
setReadOnly
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setSizeFull, setSizeUndefined, setWidth, setWidth
 

Constructor Detail

JPAContainerCustomField

public JPAContainerCustomField()
Method Detail

getType

public abstract Class<T> getType()
Specified by:
getType in interface com.vaadin.data.Property<T>

isReadOnly

public boolean isReadOnly()
Specified by:
isReadOnly in interface com.vaadin.data.Property<T>
Specified by:
isReadOnly in interface com.vaadin.ui.Component
Overrides:
isReadOnly in class com.vaadin.ui.AbstractComponent

isInvalidCommitted

public boolean isInvalidCommitted()
Specified by:
isInvalidCommitted in interface com.vaadin.data.BufferedValidatable

setInvalidCommitted

public void setInvalidCommitted(boolean isCommitted)
Specified by:
setInvalidCommitted in interface com.vaadin.data.BufferedValidatable

commit

public void commit()
            throws com.vaadin.data.Buffered.SourceException,
                   com.vaadin.data.Validator.InvalidValueException
Specified by:
commit in interface com.vaadin.data.Buffered
Throws:
com.vaadin.data.Buffered.SourceException
com.vaadin.data.Validator.InvalidValueException

discard

public void discard()
             throws com.vaadin.data.Buffered.SourceException
Specified by:
discard in interface com.vaadin.data.Buffered
Throws:
com.vaadin.data.Buffered.SourceException

isModified

public boolean isModified()
Specified by:
isModified in interface com.vaadin.data.Buffered

isWriteThrough

public boolean isWriteThrough()

setWriteThrough

public void setWriteThrough(boolean writeTrough)
                     throws com.vaadin.data.Buffered.SourceException,
                            com.vaadin.data.Validator.InvalidValueException
Throws:
com.vaadin.data.Buffered.SourceException
com.vaadin.data.Validator.InvalidValueException

isReadThrough

public boolean isReadThrough()

setReadThrough

public void setReadThrough(boolean readTrough)
                    throws com.vaadin.data.Buffered.SourceException
Throws:
com.vaadin.data.Buffered.SourceException

toString

public String toString()
Returns the value of the Property in human readable textual format.

Overrides:
toString in class Object
See Also:
Object.toString()

getValue

public T getValue()
Gets the current value of the field.

This is the visible, modified and possible invalid value the user have entered to the field. In the read-through mode, the abstract buffer is also updated and validation is performed.

Note that the object returned is compatible with getType(). For example, if the type is String, this returns Strings even when the underlying datasource is of some other type. In order to access the datasources native type, use getPropertyDatasource().getValue() instead.

Note that when you extend CustomField, you must reimplement this method if datasource.getValue() is not assignable to class returned by getType() AND getType() is not String. In case of Strings, getValue() calls datasource.toString() instead of datasource.getValue().

Specified by:
getValue in interface com.vaadin.data.Property<T>
Returns:
the current value of the field.

setValue

public void setValue(Object newValue)
              throws com.vaadin.data.Property.ReadOnlyException
Specified by:
setValue in interface com.vaadin.data.Property<T>
Throws:
com.vaadin.data.Property.ReadOnlyException

setValue

protected void setValue(Object newValue,
                        boolean repaintIsNotNeeded)
                 throws com.vaadin.data.Property.ReadOnlyException
Sets the value of the field.

Parameters:
newValue - the New value of the field.
repaintIsNotNeeded - True iff caller is sure that repaint is not needed.
Throws:
Property.ReadOnlyException
Property.ConversionException

getPropertyDataSource

public com.vaadin.data.Property<T> getPropertyDataSource()
Specified by:
getPropertyDataSource in interface com.vaadin.data.Property.Viewer

setPropertyDataSource

public void setPropertyDataSource(com.vaadin.data.Property newDataSource)

Sets the specified Property as the data source for the field. All uncommitted changes to the field are discarded and the value is refreshed from the new data source.

If the datasource has any validators, the same validators are added to the field. Because the default behavior of the field is to allow invalid values, but not to allow committing them, this only adds visual error messages to fields and do not allow committing them as long as the value is invalid. After the value is valid, the error message is not shown and the commit can be done normally.

Specified by:
setPropertyDataSource in interface com.vaadin.data.Property.Viewer
Parameters:
newDataSource - the new data source Property.

addValidator

public void addValidator(com.vaadin.data.Validator validator)
Specified by:
addValidator in interface com.vaadin.data.Validatable

getValidators

public Collection<com.vaadin.data.Validator> getValidators()
Gets the validators of the field.

Specified by:
getValidators in interface com.vaadin.data.Validatable
Returns:
the Unmodifiable collection that holds all validators for the field, not null.

removeValidator

public void removeValidator(com.vaadin.data.Validator validator)
Removes the validator from the field.

Specified by:
removeValidator in interface com.vaadin.data.Validatable
Parameters:
validator - the validator to remove.

isValid

public boolean isValid()
Tests the current value against all registered validators.

Specified by:
isValid in interface com.vaadin.data.Validatable
Returns:
true if all registered validators claim that the current value is valid, false otherwise.

validate

public void validate()
              throws com.vaadin.data.Validator.InvalidValueException
Checks the validity of the Validatable by validating the field with all attached validators. The "required" validation is a built-in validation feature. If the field is required, but empty, validation will throw an EmptyValueException with the error message set with setRequiredError().

Specified by:
validate in interface com.vaadin.data.Validatable
Throws:
com.vaadin.data.Validator.InvalidValueException
See Also:
Validatable.validate()

isInvalidAllowed

public boolean isInvalidAllowed()
Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately.

Specified by:
isInvalidAllowed in interface com.vaadin.data.Validatable
Returns:
true iff the invalid values are allowed.
See Also:
Validatable.isInvalidAllowed()

setInvalidAllowed

public void setInvalidAllowed(boolean invalidAllowed)
                       throws UnsupportedOperationException
Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately.

In common setting where the user wants to assure the correctness of the datasource, but allow temporarily invalid contents in the field, the user should add the validators to datasource, that should not allow invalid values. The validators are automatically copied to the field when the datasource is set.

Specified by:
setInvalidAllowed in interface com.vaadin.data.Validatable
Throws:
UnsupportedOperationException
See Also:
Validatable.setInvalidAllowed(boolean)

getErrorMessage

public com.vaadin.server.ErrorMessage getErrorMessage()
Error messages shown by the fields are composites of the error message thrown by the superclasses (that is the component error message), validation errors and buffered source errors.

Overrides:
getErrorMessage in class com.vaadin.ui.AbstractComponent
See Also:
AbstractComponent.getErrorMessage()

addListener

@Deprecated
public void addListener(com.vaadin.data.Property.ValueChangeListener listener)
Deprecated. 

Specified by:
addListener in interface com.vaadin.data.Property.ValueChangeNotifier

addValueChangeListener

public void addValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
addValueChangeListener in interface com.vaadin.data.Property.ValueChangeNotifier

removeListener

@Deprecated
public void removeListener(com.vaadin.data.Property.ValueChangeListener listener)
Deprecated. 

Specified by:
removeListener in interface com.vaadin.data.Property.ValueChangeNotifier

removeValueChangeListener

public void removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
removeValueChangeListener in interface com.vaadin.data.Property.ValueChangeNotifier

fireValueChange

protected void fireValueChange(boolean repaintIsNotNeeded)
Emits the value change event. The value contained in the field is validated before the event is created.


valueChange

public void valueChange(com.vaadin.data.Property.ValueChangeEvent event)
This method listens to data source value changes and passes the changes forwards.

Specified by:
valueChange in interface com.vaadin.data.Property.ValueChangeListener
Parameters:
event - the value change event telling the data source contents have changed.

focus

public void focus()
Specified by:
focus in interface com.vaadin.ui.Component.Focusable
Overrides:
focus in class com.vaadin.ui.AbstractComponent

getTabIndex

public int getTabIndex()
Specified by:
getTabIndex in interface com.vaadin.ui.Component.Focusable

setTabIndex

public void setTabIndex(int tabIndex)
Specified by:
setTabIndex in interface com.vaadin.ui.Component.Focusable

setInternalValue

protected void setInternalValue(T newValue)
Sets the internal field value. This is purely used by CustomField to change the internal Field value. It does not trigger valuechange events. It can be overriden by the inheriting classes to update all dependent variables.

Parameters:
newValue - the new value to be set.

isRequired

public boolean isRequired()
Is this field required. Required fields must filled by the user. If the field is required, it is visually indicated in the user interface. Furthermore, setting field to be required implicitly adds "non-empty" validator and thus isValid() == false or any isEmpty() fields. In those cases validation errors are not painted as it is obvious that the user must fill in the required fields. On the other hand, for the non-required fields isValid() == true if the field isEmpty() regardless of any attached validators.

Specified by:
isRequired in interface com.vaadin.ui.Field<T>
Returns:
true if the field is required .otherwise false.

setRequired

public void setRequired(boolean required)
Sets the field required. Required fields must filled by the user. If the field is required, it is visually indicated in the user interface. Furthermore, setting field to be required implicitly adds "non-empty" validator and thus isValid() == false or any isEmpty() fields. In those cases validation errors are not painted as it is obvious that the user must fill in the required fields. On the other hand, for the non-required fields isValid() == true if the field isEmpty() regardless of any attached validators.

Specified by:
setRequired in interface com.vaadin.ui.Field<T>
Parameters:
required - Is the field required.

setRequiredError

public void setRequiredError(String requiredMessage)
Set the error that is show if this field is required, but empty. When setting requiredMessage to be "" or null, no error pop-up or exclamation mark is shown for a empty required field. This faults to "". Even in those cases isValid() returns false for empty required fields.

Specified by:
setRequiredError in interface com.vaadin.ui.Field<T>
Parameters:
requiredMessage - Message to be shown when this field is required, but empty.

getRequiredError

public String getRequiredError()
Specified by:
getRequiredError in interface com.vaadin.ui.Field<T>

isEmpty

protected boolean isEmpty()
Is the field empty? In general, "empty" state is same as null..


isValidationVisible

public boolean isValidationVisible()
Is automatic, visible validation enabled? If automatic validation is enabled, any validators connected to this component are evaluated while painting the component and potential error messages are sent to client. If the automatic validation is turned off, isValid() and validate() methods still work, but one must show the validation in their own code.

Returns:
True, if automatic validation is enabled.

setValidationVisible

public void setValidationVisible(boolean validateAutomatically)
Enable or disable automatic, visible validation. If automatic validation is enabled, any validators connected to this component are evaluated while painting the component and potential error messages are sent to client. If the automatic validation is turned off, isValid() and validate() methods still work, but one must show the validation in their own code.

Parameters:
validateAutomatically - True, if automatic validation is enabled.

setCurrentBufferedSourceException

public void setCurrentBufferedSourceException(com.vaadin.data.Buffered.SourceException currentBufferedSourceException)


Copyright © 2013 Vaadin Ltd. All rights reserved.