ADAPTER
- is the generic type of AbstractUiWidgetNative.getWidgetAdapter()
.VALUE
- is the generic type of the value
.ADAPTER_VALUE
- is the generic type of the adapter
value.public abstract class AbstractUiWidgetField<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE,ADAPTER_VALUE> extends AbstractUiWidgetActive<ADAPTER,VALUE> implements UiWidgetField<VALUE>
UiWidgetField
.AbstractUiWidgetNative.SizeImpl
AbstractUiWidget.AccessHelper, AbstractUiWidget.EventSender, AbstractUiWidget.HandlerContainer
Modifier and Type | Field and Description |
---|---|
private String |
fieldLabel |
private AbstractUiWidgetLabel<?> |
fieldLabelWidget |
private boolean |
trimValue |
private String |
validationFailure |
private String |
valueAsString |
STYLE_FIELD, STYLE_LABEL, STYLE_MANDATORY, STYLE_VIEW
STYLE_HEADER
HTML_ATTRIBUTE_ID, ID_SEPARATOR, PROPERTY_ID
PROPERTY_STYLES, STYLE_PATTERN_MULTIPLE, STYLE_PATTERN_SINGLE
WAI_ARIA
PROPERTY_LABEL
ACCESS_KEY_NONE, HTML_ATTRIBUTE_ACCESS_KEY
Constructor and Description |
---|
AbstractUiWidgetField(UiContext context,
ADAPTER widgetAdapter)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
clearValidationFailure()
This method clears the messages locally (the non-recursive part of
AbstractUiWidget.clearMessages() ). |
protected ADAPTER_VALUE |
convertFromValue(VALUE widgetValue)
This method converts the given
widgetValue to the type used by the
widget adapter . |
protected VALUE |
convertToValue(ADAPTER_VALUE adapterValue,
ValidationState state)
|
protected VALUE |
doGetValue(VALUE template,
ValidationState state)
This method is called from the
data-binding triggered by API methods such as
AbstractUiFeatureValueAndValidation.getValue() . |
protected void |
doSetValue(VALUE newValue,
boolean forUser)
This method is called from the
data-binding triggered by API methods such as
AbstractUiWidget.setValue(Object, boolean) . |
String |
getLabel()
This method gets the label of this object.
|
UiWidgetLabel |
getLabelWidget()
This method gets the
label widget associated with this field. |
protected ADAPTER_VALUE |
getNullValue()
This method gets the result of
convertFromValue(Object) for the value null . |
String |
getSource() |
String |
getValidationFailure()
This method gets the validation failure of this object.
|
String |
getValueAsString()
|
protected abstract Class<VALUE> |
getValueClass() |
VALUE |
getValueDirect(VALUE template,
ValidationState state)
This method is a combination of
AttributeReadValueAdvanced.getValueOrException(Object) and
AbstractValidatableObject.validate(ValidationState) . |
protected void |
initializeWidgetAdapter(ADAPTER adapter)
This method is called from
AbstractUiWidgetNative.getWidgetAdapter() to initialize the UiWidgetAdapter . |
boolean |
isTrimValue()
|
void |
setId(String newId)
This method set the
ID of this object. |
void |
setLabel(String label)
This method sets the
label of this object. |
protected void |
setMandatory(boolean mandatory)
This method is called whenever the
AbstractUiWidget.isMandatory() flag is updated. |
void |
setTrimValue(boolean trimValue)
This method sets the
trimValue flag. |
void |
setValidationFailure(String validationFailure)
This method sets the
validation failure . |
void |
setValue(VALUE newValue,
boolean forUser)
This is the generic variant of
AttributeWriteValueAdvanced.setValue(Object) and AttributeWriteValueAdvanced.setValueForUser(Object) . |
void |
setValueAsString(String value)
This method sets the
valueAsString of this object. |
void |
setVisible(boolean visible,
boolean programmatic)
This method shows or hides this object.
|
String |
toString() |
private void |
updateFieldLabel()
Updates the
field label in field label widget . |
addFocusHandler, getAccessKey, isFocused, onAccessKeyPressed, removeFocusHandler, setAccessKey, setFocused, setFocused
addChangeHandler, addStyle, clearMessages, clearValidity, createSize, createUniqueId, createWidgetAdapter, dispose, doSetMode, doValidate, getAriaRole, getAriaRoleFixedType, getChild, getChild, getChildCount, getChildIndex, getId, getIndexOfStyle, getMode, getModeFixed, getParent, getPrimaryStyle, getSize, getStyles, getTooltip, getVisibleFlag, getWidgetAdapter, getWidgetAdapter, hasStyle, hasWidgetAdapter, isDisposed, isEnabled, isModifiedRecursive, isVisible, isVisibleRecursive, removeChangeHandler, removeFromParent, removeStyle, setAriaRole, setEnabled, setIdPrefix, setMode, setMode, setModeFixed, setParent, setPrimaryStyle, setStyles, setTooltip, setVisible, visibilityChanged
addEventHandler, addValidator, clearMessagesLocal, convertValueToString, fireEvent, fireValueChange, getBasicUtil, getContext, getDataBinding, getDataBinding, getDataBindingForWidget, getEventSender, getFactory, getLogger, getObserverSource, getOriginalValue, getRecentValue, getValueOrException, getWidgetAdapter, hasEventSender, isMandatory, isModified, removeEventHandler, removeFromParent, removeValidator, setModified, setParent
addValidatorMandatory, createValidationFailure, getValue, getValueAndValidate, handleGetValueError, resetValue, setValue, setValueForUser, validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getChild, getChild
getChildCount, getChildIndex
getContext, getParent, getSize
clearMessages
addEventHandler, removeEventHandler
setMode
getMode
setModeFixed
getModeFixed
getId
setTooltip
getTooltip
getVisibleFlag, isVisible, setVisible
isVisibleRecursive
setEnabled
isEnabled
addStyle, removeStyle
hasStyle
setStyles
getStyles
setPrimaryStyle
getPrimaryStyle
dispose
isDisposed
isModified
getAriaRole
getValue
getValueAndValidate
addChangeHandler, removeChangeHandler
resetValue, setValue, setValueForUser
getOriginalValue, getValueOrException
addValidatorMandatory, isMandatory
addValidator, removeValidator
setAccessKey
getAccessKey
addFocusHandler, removeFocusHandler
isFocused
setFocused
private String validationFailure
getValidationFailure()
private String fieldLabel
getLabel()
private AbstractUiWidgetLabel<?> fieldLabelWidget
getLabelWidget()
private String valueAsString
getValueAsString()
private boolean trimValue
isTrimValue()
public AbstractUiWidgetField(UiContext context, ADAPTER widgetAdapter)
context
- is the context
.widgetAdapter
- is the widget adapter
. Typically null
for
lazy initialization.protected void initializeWidgetAdapter(ADAPTER adapter)
AbstractUiWidgetNative.getWidgetAdapter()
to initialize the UiWidgetAdapter
. All
attributes of this widget need to be set in the UiWidgetAdapter
.initializeWidgetAdapter
in class AbstractUiWidgetActive<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
adapter
- is the UiWidgetAdapter
to initialize.protected abstract Class<VALUE> getValueClass()
getValueClass
in class AbstractUiWidget<VALUE>
Class
reflecting <VALUE>. May also be null
for Void
.protected VALUE doGetValue(VALUE template, ValidationState state) throws RuntimeException
data-binding
triggered by API methods such as
AbstractUiFeatureValueAndValidation.getValue()
. In many cases the data-binding
already performs the
required work to do. However, here is the place to implemented the custom logic to get the value from the
actual widget. The following cases have to be distinguished:
native
fields
this method has to get the actual
value from the underlying native widget (text-box, password-field, etc.).custom fields
this
method will be responsible to convert from the delegates value (see
UiWidgetCustom.getDelegate()
) to the proper value type. E.g. if you want to create a custom
widget to edit your own datatype such as CustomerNumber
based on a
UiWidgetTextField
you need to convert from String
to CustomerNumber
.custom composite widgets
you should use AbstractUiWidget.getDataBinding()
.
UiDataBinding.createAndBind(net.sf.mmm.util.pojo.path.api.TypedProperty)
that gives you high-level support and makes your live easy. Then there is no need to override this
method.Void
, there is nothing to do here.AbstractUiWidget.doSetValue(Object, boolean)
.doGetValue
in class AbstractUiWidgetNative<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
template
- is the object where the data is filled in. May only be null
if according to
data-binding
(e.g. if <VALUE> is an (immutable)
Datatype
).state
- is the ValidationState
. May be null
(if the validation is omitted).
Should only be used to propagate to AbstractUiWidget.getValueDirect(Object, ValidationState)
of children.null
if empty. If <VALUE> is
String
the empty String
has to be returned if no value has been entered. In case
<VALUE> is a mutable object (java bean) the template
is NOT
null
and is to be returned by this method after the value(s) of this widget have
been assigned. For immutable datatypes
template
will be null
and this method has to create a new instance of
<VALUE> based on the end-users input in the widget.RuntimeException
AbstractUiWidget.doSetValue(Object, boolean)
public final boolean isTrimValue()
value
of this object should be automatically trimmed
. The default value is
true
. E.g. if a text field widget supports this property and it is true
the
value entered by the end-user will automatically be trimmed
. If you want prevent
this (e.g. if the end-user shall provide a separator, indentation, substitution variable, or the like)
you need to set
it to false
.isTrimValue
in interface AttributeReadTrimValue
true
if the value
of this object should be automatically trimmed
.public final void setTrimValue(boolean trimValue)
trimValue
flag.setTrimValue
in interface AttributeWriteTrimValue
trimValue
- is the new value of AttributeReadTrimValue.isTrimValue()
.protected void doSetValue(VALUE newValue, boolean forUser)
data-binding
triggered by API methods such as
AbstractUiWidget.setValue(Object, boolean)
. In many cases the data-binding
already
performs the required work to do. However, here is the place to implemented the custom logic to get the
value from the actual widget. For details see AbstractUiWidget.doGetValue(Object, ValidationState)
.doSetValue
in class AbstractUiWidgetNative<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
newValue
- is the value to set. Typically a composite object (e.g. java bean) so its attributes are set
to fields (see UiWidgetField
).forUser
- true
if called from AbstractUiFeatureValueAndValidation.setValueForUser(Object)
, false
if
set from AbstractUiFeatureValueAndValidation.setValue(Object)
.AbstractUiWidget.doGetValue(Object, ValidationState)
protected VALUE convertToValue(ADAPTER_VALUE adapterValue, ValidationState state)
adapterValue
from the widget
adapter
to the type of this value
. The default implementation simply performs a
cast. You have to override this method if <VALUE> and <WIDGET_VALUE> differ.adapterValue
- is the value to convert. Will NOT be null.state
- is the ValidationState
or null
if not called without validation.protected ADAPTER_VALUE getNullValue()
convertFromValue(Object)
for the value null
. It is
called for null
values instead of convertFromValue(Object)
to prevent
NullPointerException
s. The default is null
- override to change.null
for the widget adapter
.protected ADAPTER_VALUE convertFromValue(VALUE widgetValue)
widgetValue
to the type used by the
widget adapter
. The default implementation simply performs a cast. You have
to override this method if <VALUE> and <WIDGET_VALUE> differ.widgetValue
- is the value to convert. Will NOT be null
(See getNullValue()
).public void setValue(VALUE newValue, boolean forUser)
AttributeWriteValueAdvanced.setValue(Object)
and AttributeWriteValueAdvanced.setValueForUser(Object)
. forUser
is dynamic.setValue
in interface AttributeWriteValueAdvanced<VALUE>
setValue
in class AbstractUiWidget<VALUE>
newValue
- is the new value to set.forUser
- true
for the semantics of AttributeWriteValueAdvanced.setValueForUser(Object)
,
false
for AttributeWriteValueAdvanced.setValue(Object)
.public String getValueAsString()
value
as
String
. It returns the value as it is entered by the end-user that may be invalid.getValueAsString
in interface AttributeReadValueAsString
String
if the field is blank.public void setValueAsString(String value)
valueAsString
of this object. setValueAsString
in interface AttributeWriteValueAsString
value
- is the new value
as it would have been entered by the user.public String getValidationFailure()
getValidationFailure
in interface AttributeReadValidationFailure
null
for no error.public void setValidationFailure(String validationFailure)
validation failure
. UiFeatureValidation
. This
method is only intended as back-door for very special cases (e.g. you have to use your own validator
infrastructure and perform validation outside this framework). It is not recommended to use this method
as an API user.setValidationFailure
in interface AttributeWriteValidationFailure
validationFailure
- is the validation failure text. The empty string or null
will clear
the error and mark the field as valid. Otherwise the field will be invalid.protected void clearValidationFailure()
AbstractUiWidget.clearMessages()
).clearValidationFailure
in class AbstractUiWidget<VALUE>
public String getLabel()
UiWidgetField
) has an associated label widget
. This
method gets its label text. Please note that the label widget
is not contained
in this field widget itself, so if you regularly add this field widget to some other widget you will not
see the label. However, UiWidgetGridPanel
also
automatically
adds
the label widget
. The recommended use-case is to create a form to view
and edit your business object extending
UiWidgetCustomGridPanel
and use
UiDataBinding
. UiWidgetField.getLabelWidget()
.getLabel()
this method
prevents actually creating the label widget
if it does NOT yet exist. Further
it will only return what has been set via UiWidgetField.setLabel(String)
and NOT what has potentially been set
via UiWidgetField.getLabelWidget()
. setLabel
(what should be avoided).getLabel
in interface AttributeReadLabel
getLabel
in interface UiWidgetField<VALUE>
public void setLabel(String label)
label
of this object.setLabel
in interface AttributeWriteLabel
setLabel
in interface UiWidgetField<VALUE>
label
- is the new label
to set.UiWidgetField.getLabel()
private void updateFieldLabel()
field label
in field label widget
.protected void setMandatory(boolean mandatory)
AbstractUiWidget.isMandatory()
flag is updated. You may override it to update
the UI to reflect this change.setMandatory
in class AbstractUiWidget<VALUE>
mandatory
- is the new value of AbstractUiWidget.isMandatory()
.public final UiWidgetLabel getLabelWidget()
label widget
associated with this field. UiWidgetField.getLabel()
and
UiWidgetField.setLabel(String)
. Be aware that some native toolkits (e.g. SmartGWT) already implement field
widgets including the label. In this case this method will return a different view on the same native
widget.getLabelWidget
in interface UiWidgetField<VALUE>
public void setId(String newId)
ID
of this object. Use this method to give the object a meaningful
identifier after creation. AttributeReadHtmlId.getId()
for the syntax constraints of IDs.setId
in interface AttributeWriteHtmlId
setId
in interface AttributeWriteId<String>
setId
in class AbstractUiWidgetNative<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
newId
- is the new ID
for the object.public String toString()
toString
in class AbstractUiWidgetNative<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
public VALUE getValueDirect(VALUE template, ValidationState state) throws RuntimeException
AttributeReadValueAdvanced.getValueOrException(Object)
and
AbstractValidatableObject.validate(ValidationState)
. It allows more efficient implementations as determining and creating
the value
can be expensive. Saving changes requires validation AND
on success getting the value, while already validation requires getting the value. For composite UI
objects this effect would reinforce to multiply the number of calls to
AttributeReadValueAdvanced.getValueOrException(Object)
. UiFeatureValueAndValidation.getValueAndValidate(ValidationState)
.getValueDirect
in interface UiFeatureValueAndValidation<VALUE>
getValueDirect
in class AbstractUiWidget<VALUE>
template
- is the object where the data is filled in. May also be null
- then this
method will create a new instance.state
- is the ValidationState
. If null
the validation will be omitted,
otherwise an implicit validation is performed.current value
. May be null
(esp. if invalid).RuntimeException
- if state
is null
no validation is performed and input
errors are directly thrown causing a fast fail. Otherwise if validation is performed all
RuntimeException
are catched and according validation failures are
collected
and
visualized by the UI.public void setVisible(boolean visible, boolean programmatic)
setVisible
in interface AttributeWriteVisibleAdvanced
setVisible
in class AbstractUiWidgetNative<ADAPTER extends UiWidgetAdapterField<VALUE,ADAPTER_VALUE>,VALUE>
visible
- - see AbstractUiWidgetNative.setVisible(boolean)
.programmatic
- - see UiEvent.isProgrammatic()
.AbstractUiWidgetNative.setVisible(boolean)
public String getSource()
getSource
in class AbstractUiWidget<VALUE>
String
representation of this object that qualifies as source description that might be
displayed to end-users (unlike AbstractUiWidget.toString()
what is for debugging only).Copyright © 2001–2016 mmm-Team. All rights reserved.