public class Text extends ContextBean implements Param.UnnamedParametric
Render a I18n text message.
The message must be in a resource bundle with the same name as the action that it is associated with. In practice this means that you should create a properties file in the same package as your Java class with the same name as your class, but with .properties extension.
If the named message is not found in a property file, then the body of the tag will be used as default message. If no value is found, the key of the message will not be written out.
Example:
Accessing messages from a given bundle (the i18n Shop example bundle in the first example) and using bundle defined through the framework in the second example.
<!-- First Example --> <s:i18n name="struts.action.test.i18n.Shop"> <s:text name="main.title"/> </s:i18n> <!-- Second Example --> <s:text name="main.title" /> <!-- Third Examlpe --> <s:text name="i18n.label.greetings"> <s:param >Mr Smith</s:param> </s:text>
<-- Fourth Example --> <s:text name="some.key" /> <-- Fifth Example --> <s:text name="some.invalid.key" > The Default Message That Will Be Displayed </s:text>
Param
Modifier and Type | Field and Description |
---|---|
protected String |
actualName |
protected String |
name |
protected List<Object> |
values |
var
actionMapper, COMPONENT_STACK, devMode, parameters, stack, standardAttributesMap, throwExceptionOnELFailure
Constructor and Description |
---|
Text(ValueStack stack) |
Modifier and Type | Method and Description |
---|---|
void |
addParameter(Object value)
Adds the given value as a parameter to the outer tag.
|
void |
addParameter(String key,
Object value)
Adds the given key and value to this component's own parameter.
|
boolean |
end(Writer writer,
String body)
Callback for the end tag of this component.
|
void |
setEscapeCsv(boolean escapeCsv) |
void |
setEscapeHtml(boolean escape) |
void |
setEscapeJavaScript(boolean escapeJavaScript) |
void |
setEscapeXml(boolean escapeXml) |
void |
setName(String name) |
boolean |
usesBody()
Overwrite to set if body should be used.
|
getVar, putInContext, setVar
addAllParameters, altSyntax, completeExpressionIfAltSyntax, copyParams, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findStringIfAltSyntax, findValue, findValue, findValue, getComponentStack, getParameters, getStack, getStandardAttributes, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpressionIfAltSyntax, toString
public Text(ValueStack stack)
public void setName(String name)
public void setEscapeHtml(boolean escape)
public void setEscapeJavaScript(boolean escapeJavaScript)
public void setEscapeXml(boolean escapeXml)
public void setEscapeCsv(boolean escapeCsv)
public boolean usesBody()
Component
public boolean end(Writer writer, String body)
Component
public void addParameter(String key, Object value)
Component
addParameter
in class Component
key
- the key of the new parameter to add.value
- the value associated with the key.public void addParameter(Object value)
Param.UnnamedParametric
addParameter
in interface Param.UnnamedParametric
value
- the valueCopyright © 2000–2020 Apache Software Foundation. All rights reserved.