Class WText
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.WText
-
- All Implemented Interfaces:
BeanAware,BeanBound,BeanProviderBound,DataBound,WComponent,WebComponent,Serializable
- Direct Known Subclasses:
WAbbrText,WFilterText,WHeading,WStyledText
public class WText extends WBeanComponent
WText is used to render some basic/raw text.
- Since:
- 1.0.0
- Author:
- Adam Millard, Yiannis Paschalidis - rewritten as a bean aware component in Sfp_Common10
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWText.TextModelComponent model for WText.-
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 WText()Creates an empty WText.WText(String text, Serializable... args)Creates a WText with the given initial text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WText.TextModelgetComponentModel()Returns the effective component model for this component.ObjectgetData()Returns the data for this component.protected WText.TextModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.StringgetText()booleanisEncodeText()Indicates whether the heading text needs to be encoded.booleanisSanitizeOnOutput()protected WText.TextModelnewComponentModel()Creates a new component model appropriate for this component.protected StringsanitizeOutputText(String text)voidsetEncodeText(boolean encodeText)Sets whether the text needs to be encoded.voidsetSanitizeOnOutput(boolean sanitize)Pass true if you need to run the HTML sanitizer on any output.voidsetText(String text, Serializable... args)Sets the text.StringtoString()Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
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, getId, 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
-
-
-
-
Constructor Detail
-
WText
public WText()
Creates an empty WText.
-
WText
public WText(String text, Serializable... args)
Creates a WText with the given initial text.- Parameters:
text- the text to display, usingMessageFormatsyntax.args- optional arguments for the message format string.// Will display the text "Hello world" new WText("Hello world");// Will display "Secret agent James Bond, 007" new WText("Secret agent {0}, {1,number,000}", "James Bond", 7);
-
-
Method Detail
-
getData
public Object getData()
Returns the data for this component. The following are searched in order:- a value set explicitly in the ui context using
WBeanComponent.setData(Object); - if a bean is available; the bean's value; or
- the value set on the shared model.
- Specified by:
getDatain interfaceDataBound- Overrides:
getDatain classWBeanComponent- Returns:
- the current value of this component for the given context
- a value set explicitly in the ui context using
-
getText
public String getText()
- Returns:
- the current text.
-
setText
public void setText(String text, Serializable... args)
Sets the text.
NOTE: If the text is dynamically generated, it may be preferable to override
getText()instead. This will reduce the amount of data which is stored in the user session.- Parameters:
text- the text to set, usingMessageFormatsyntax.args- optional arguments for the message format string.// Changes the text to "Hello world" myText.setText("Hello world");// Changes the text to "Secret agent James Bond, 007" new WText("Secret agent {0}, {1,number,000}", "James Bond", 7);
-
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 text needs to be encoded.
When setting
encodeTexttofalse, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.WARNING: If you are using WText to display "user entered" or untrusted data, use of this method with
encodeTextset tofalsemay result in security issues.WARNING: Avoid using WText to add excessive amounts of HTML mark-up to the UI. Embedded mark-up is more likely to break in future WComponent releases. If you are attempting to use WText for layout purposes, consider using a
LayoutManagerinstead. For example,new WText("<br>")could be rewritten to use theFlowLayoutlayout with a vertical layout direction.- Parameters:
encodeText- true if the text needs to be encoded, false if not.
-
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
-
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 WText.TextModel newComponentModel()
Creates a new component model appropriate for this component.- Overrides:
newComponentModelin classWBeanComponent- Returns:
- a TextModel
-
getOrCreateComponentModel
protected WText.TextModel 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 classWBeanComponent- Returns:
- the model for this component
-
getComponentModel
protected WText.TextModel 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 classWBeanComponent- Returns:
- the effective component model
-
-