Class Text

  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.ContextBean
          extended by org.apache.struts2.components.Text
All Implemented Interfaces:

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 body is used, then the stack will be searched, and if a value is returned, it will written to the output. If no value is found on the stack, the key of the message will be written out.



 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"/>

 <!-- Second Example -->
 <s:text name="main.title" />

 <!-- Third Examlpe -->
 <s:text name="i18n.label.greetings">
    <s:param >Mr Smith</s:param>


 <-- Fourth Example -->
 <s:text name="some.key" />

 <-- Fifth Example -->
 <s:text name="some.invalid.key" >
    The Default Message That Will Be Displayed


See Also:

Field Summary
protected  java.lang.String actualName
protected  java.lang.String name
protected  java.lang.String searchStack
protected  java.util.List values
Fields inherited from class org.apache.struts2.components.ContextBean
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, parameters, stack, throwExceptionOnELFailure
Constructor Summary
Text(ValueStack stack)
Method Summary
 void addParameter(java.lang.Object value)
          Adds the given value as a parameter to the outer tag.
 void addParameter(java.lang.String key, java.lang.Object value)
          Adds the given key and value to this component's own parameter.
 boolean end( writer, java.lang.String body)
          Callback for the end tag of this component.
 void setName(java.lang.String name)
 void setSearchValueStack(java.lang.String searchStack)
 boolean usesBody()
          Overwrite to set if body shold be used.
Methods inherited from class org.apache.struts2.components.ContextBean
getVar, putInContext, setId, setVar
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, altSyntax, altSyntax, completeExpressionIfAltSyntax, copyParams, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findStringIfAltSyntax, findValue, findValue, findValue, getComponentStack, getParameters, getStack, popComponentStack, setActionMapper, setThrowExceptionsOnELFailure, start, stripExpressionIfAltSyntax, stripExpressionIfAltSyntax, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected java.util.List values


protected java.lang.String actualName


protected java.lang.String name


protected java.lang.String searchStack
Constructor Detail


public Text(ValueStack stack)
Method Detail


public void setName(java.lang.String name)


public void setSearchValueStack(java.lang.String searchStack)


public boolean usesBody()
Description copied from class: Component
Overwrite to set if body shold be used.

usesBody in class Component
always false for this component.


public boolean end( writer,
                   java.lang.String body)
Description copied from class: Component
Callback for the end tag of this component. Should the body be evaluated again?

NOTE: will pop component stack.

end in class Component
writer - the output writer.
body - the rendered body.
true if the body should be evaluated again


public void addParameter(java.lang.String key,
                         java.lang.Object value)
Description copied from class: Component
Adds the given key and value to this component's own parameter.

If the provided key is null nothing happens. If the provided value is null any existing parameter with the given key name is removed.

addParameter in class Component
key - the key of the new parameter to add.
value - the value assoicated with the key.


public void addParameter(java.lang.Object value)
Description copied from interface: Param.UnnamedParametric
Adds the given value as a parameter to the outer tag.

Specified by:
addParameter in interface Param.UnnamedParametric
value - the value

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.