Class WLabel
-
- All Implemented Interfaces:
AccessKeyable
,AjaxTarget
,Container
,MutableContainer
,NamingContextable
,WComponent
,WebComponent
,Serializable
public class WLabel extends AbstractMutableContainer implements AjaxTarget, AccessKeyable
The WLabel component is used to display a textual label for an input field. A WLabel is associated with an input field provided in the labels constructor, or via the
setForComponent
method.- Since:
- 1.0.0
- Author:
- James Gifford
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WLabel.LabelModel
Holds the extrinsic state information of a WLabel.-
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
-
-
Constructor Summary
Constructors Constructor Description WLabel()
Creates an empty WLabel.WLabel(String text)
Creates a new WLabel with the specified text.WLabel(String text, char accessKey)
Creates a new WLabel with the specified text and access key.WLabel(String text, char accessKey, WComponent forComponent)
Creates a new WLabel.WLabel(String text, WComponent forComponent)
Creates a new WLabel with the specified text and component that the label is for.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(WComponent component)
Adds the given component as a child of this component.char
getAccessKey()
protected WLabel.LabelModel
getComponentModel()
Returns the effective component model for this component.WComponent
getForComponent()
String
getHint()
String
getId()
Return an identifier for this component, generating one if necessary.String
getLabelFor()
protected WLabel.LabelModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.String
getText()
boolean
isEncodeText()
Indicates whether the heading text needs to be encoded.boolean
isSanitizeOnOutput()
protected WLabel.LabelModel
newComponentModel()
Creates a new model appropriate for this component.protected String
sanitizeOutputText(String text)
void
setAccessKey(char accessKey)
Set the key (in combination with Alt) that should give focus to this label.void
setEncodeText(boolean encodeText)
Sets whether the heading text needs to be encoded.void
setForComponent(WComponent forComponent)
Sets the component that this label is associated with.void
setHint(String hint, Serializable... args)
Sets the label "hint" text, which can be used to provide additional information to the user.void
setSanitizeOnOutput(boolean sanitize)
Pass true if you need to run the HTML sanitizer on any output.void
setText(String text, Serializable... args)
Sets the label's text.String
toString()
Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractMutableContainer
add, remove, removeAll
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractNamingContextContainer
getNamingContextId, isNamingContext, setNamingContext
-
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, getLabel, 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.AccessKeyable
getAccessKeyAsString
-
Methods inherited from interface com.github.bordertech.wcomponents.Container
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from interface com.github.bordertech.wcomponents.NamingContextable
getNamingContextId, isNamingContext
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getIdName, getInternalId, getLabel, 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
-
-
-
-
Constructor Detail
-
WLabel
public WLabel(String text, char accessKey, WComponent forComponent)
Creates a new WLabel. Sets the label text, access key and the component that label is for.- Parameters:
text
- The label text.accessKey
- The access key for the label.forComponent
- The component that this label is for.
-
WLabel
public WLabel(String text, WComponent forComponent)
Creates a new WLabel with the specified text and component that the label is for.- Parameters:
text
- the label text.forComponent
- the component that this label is for.
-
WLabel
public WLabel(String text, char accessKey)
Creates a new WLabel with the specified text and access key.- Parameters:
text
- The label text.accessKey
- The access key for the label'sforComponent
.
-
WLabel
public WLabel(String text)
Creates a new WLabel with the specified text.- Parameters:
text
- The label text.
-
WLabel
public WLabel()
Creates an empty WLabel.
-
-
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_SEPERATOR
if the parent is an active NamingContext. Then let the ID be prefix + generate unique id.
- Specified by:
getId
in interfaceWComponent
- Specified by:
getId
in interfaceWebComponent
- Overrides:
getId
in 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
-
add
public void add(WComponent component)
Adds the given component as a child of this component.- Specified by:
add
in interfaceMutableContainer
- Overrides:
add
in classAbstractMutableContainer
- Parameters:
component
- the component to add.
-
getText
public String getText()
- Returns:
- the label text.
-
setText
public void setText(String text, Serializable... args)
Sets the label's text.- Parameters:
text
- the label text, usingMessageFormat
syntax.args
- optional arguments for the message format string.
-
setHint
public void setHint(String hint, Serializable... args)
Sets the label "hint" text, which can be used to provide additional information to the user.- Parameters:
hint
- the hint text, usingMessageFormat
syntax.args
- optional arguments for the message format string.
-
getHint
public String getHint()
- Returns:
- the label hint text.
-
setForComponent
public void setForComponent(WComponent forComponent)
Sets the component that this label is associated with.- Parameters:
forComponent
- the associated component.
-
getForComponent
public WComponent getForComponent()
- Returns:
- the component that this label is associated with.
-
getLabelFor
public String getLabelFor()
- Returns:
- the id of the component that this label is for.
-
setAccessKey
public void setAccessKey(char accessKey)
Set the key (in combination with Alt) that should give focus to this label.The action that occurs when the label is focussed depends on the type of component this label is for (the
forComponent
). For example, WTextField will focus the cursor in the text input, WCheckBox will toggle the check box selection. Access keys are not case sensitive.Note: Setting the access key also sets the shared title of the component to indicate the access key combination.
- Specified by:
setAccessKey
in interfaceAccessKeyable
- Parameters:
accessKey
- The key (in combination with the Alt key) that activates this label.- Since:
- 1.0.0
-
getAccessKey
public char getAccessKey()
- Specified by:
getAccessKey
in interfaceAccessKeyable
- Returns:
- the component's access key.
-
isEncodeText
public boolean isEncodeText()
Indicates whether the heading text needs to be encoded.- Returns:
- true if the text needs to be encoded, false if not.
-
setEncodeText
public void setEncodeText(boolean encodeText)
Sets whether the heading text needs to be encoded.
When setting
encodeText
tofalse
, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.- Parameters:
encodeText
- true if the text needs to be encode, false if not.
-
toString
public String toString()
Description copied from class:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component, for debugging purposes.
-
setSanitizeOnOutput
public void setSanitizeOnOutput(boolean sanitize)
Pass true if you need to run the HTML sanitizer on any output. This is only needed if the text is not encoded as other cases the output will be XML encoded.- Parameters:
sanitize
- true if output sanitization is required.
-
isSanitizeOnOutput
public boolean isSanitizeOnOutput()
- Returns:
- true if this text area is to be sanitized on output.
-
sanitizeOutputText
protected String sanitizeOutputText(String text)
- Parameters:
text
- the output text to sanitize- Returns:
- the sanitized text
-
newComponentModel
protected WLabel.LabelModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new
WLabel.LabelModel
.
-
getComponentModel
protected WLabel.LabelModel 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:
getComponentModel
in classAbstractWComponent
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WLabel.LabelModel 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:
getOrCreateComponentModel
in classAbstractWComponent
- Returns:
- the model for this component
-
-