Class WField
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.AbstractContainer
-
- com.github.bordertech.wcomponents.WField
-
- All Implemented Interfaces:
AjaxTarget,Container,SubordinateTarget,WComponent,WebComponent,Serializable
public class WField extends AbstractContainer implements AjaxTarget, SubordinateTarget
This component is used to aggregate the common elements that are used to display an editable field (ie, the label, the field itself and an error indicator). It can only be used by adding instances to a
WFieldLayoutcomponent. If input field is not present then it renders as read only field.- Since:
- 1.0.0
- Author:
- Adam Millard
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWField.FieldModelHolds the extrinsic state information of the component.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddValidator(FieldValidator validator)Adds a validator to the input field.protected WField.FieldModelgetComponentModel()Returns the effective component model for this component.WFieldErrorIndicatorgetErrorIndicator()WComponentgetField()StringgetId()Return an identifier for this component, generating one if necessary.intgetInputWidth()Indicates the desired width of the input field, as a percentage of the available space.WLabelgetLabel()StringgetLabelText()Gets the label text (if label exists) else returnsnull.protected WField.FieldModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.WFieldWarningIndicatorgetWarningIndicator()protected WField.FieldModelnewComponentModel()Creates a new Component model.voidsetInputWidth(int inputWidth)Sets the desired width of the input field, as a percentage of the available space.voidsetLabelText(String text)Updates the label text (if label exists).voidsetMandatory(boolean mandatory)Deprecated.set mandatory directly on the required component.voidsetMandatory(boolean mandatory, String errorMessage)Deprecated.set mandatory directly on the required component.StringtoString()Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractContainer
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getIdName, getInternalId, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, handleRequest, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getIdName, getInternalId, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Method Detail
-
getId
public String getId()
Return an identifier for this component, generating one if necessary.The implementation must follow these steps in determining the Id:
If has id name set:- Find the closest ancestor to this component in the tree hierarchy that is an active
NamingContextable. - If no context found, then let the ID be the idname.
- If a context found, then let the ID be
NamingContextable.getNamingContextId()+WComponent.ID_CONTEXT_SEPERATOR+ id name.
- If the component's parent is null, then let the ID be
WComponent.DEFAULT_NO_ID. - If has a parent, then let the ID prefix be parent.getId() or parent.getNamingContextID() +
WComponent.ID_CONTEXT_SEPERATORif the parent is an active NamingContext. Then let the ID be prefix + generate unique id.
- Specified by:
getIdin interfaceWComponent- Specified by:
getIdin interfaceWebComponent- Overrides:
getIdin classAbstractWComponent- Returns:
- the id for this WComponent in the current context.
- Find the closest ancestor to this component in the tree hierarchy that is an active
-
getLabel
public WLabel getLabel()
Description copied from class:AbstractWComponent- Specified by:
getLabelin interfaceWComponent- Overrides:
getLabelin classAbstractWComponent- Returns:
- the field label
-
getField
public WComponent getField()
- Returns:
- the field
-
getErrorIndicator
public WFieldErrorIndicator getErrorIndicator()
- Returns:
- the field's error indicator
-
getWarningIndicator
public WFieldWarningIndicator getWarningIndicator()
- Returns:
- the field's warning indicator
-
setMandatory
@Deprecated public void setMandatory(boolean mandatory)
Deprecated.set mandatory directly on the required component.Sets whether this field is mandatory.The mandatory flag will only be set if the field is a
Inputcomponent orWFieldSet.- Parameters:
mandatory- true for mandatory, false for optional
-
setMandatory
@Deprecated public void setMandatory(boolean mandatory, String errorMessage)
Deprecated.set mandatory directly on the required component.Sets whether this field is mandatory.The mandatory flag will only be set if the field is a
Inputcomponent orWFieldSet.- Parameters:
mandatory- true for mandatory, false for optionalerrorMessage- the error message to display on validation error.
-
addValidator
public void addValidator(FieldValidator validator)
Adds a validator to the input field.The validator will only be added if the field is a
Inputcomponent.- Parameters:
validator- the validator to add.
-
setLabelText
public void setLabelText(String text)
Updates the label text (if label exists).- Parameters:
text- the new label text
-
getLabelText
public String getLabelText()
Gets the label text (if label exists) else returnsnull.- Returns:
- the text of the label component of this field.
-
getInputWidth
public int getInputWidth()
Indicates the desired width of the input field, as a percentage of the available space.- Returns:
- the percentage width, or 0 to use the default field width.
-
setInputWidth
public void setInputWidth(int inputWidth)
Sets the desired width of the input field, as a percentage of the available space.- Parameters:
inputWidth- the percentage width, or <= 0 to use the default field width.
-
toString
public String toString()
Description copied from class:AbstractWComponentCreates a String representation of this component; usually for debugging purposes.- Overrides:
toStringin classAbstractWComponent- Returns:
- a String representation of this component, for debugging purposes.
-
newComponentModel
protected WField.FieldModel newComponentModel()
Creates a new Component model.- Overrides:
newComponentModelin classAbstractWComponent- Returns:
- a new FieldModel.
-
getComponentModel
protected WField.FieldModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModelin classAbstractWComponent- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WField.FieldModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModelin classAbstractWComponent- Returns:
- the model for this component
-
-