Description
A tag that creates a HTML <a >.This tag supports the same attributes as the "url" tag, including nested parameters using the "param" tag.
While this tag can be used with the simple theme, xhtml theme, and others, it is really designed to work best with the ajax theme. We recommend reading the ajax a template documentation for more details. |
Parameters
Dynamic Attributes Allowed:true | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
accesskey | false | false | String | Set the html accesskey attribute on rendered html element | |
action | false | false | String | The action to generate the URL for, if not using value | |
anchor | false | false | String | The anchor for this URL | |
cssClass | false | false | String | The css class to use for element | |
cssErrorClass | false | false | String | The css error class to use for element | |
cssErrorStyle | false | false | String | The css error style definitions for element to use | |
cssStyle | false | false | String | The css style definitions for element to use | |
disabled | false | false | String | Set the html disabled attribute on rendered html element | |
encode | false | true | false | Boolean | Whether to encode parameters |
escapeAmp | false | true | false | Boolean | Specifies whether to escape ampersand (&) to (& or not |
forceAddSchemeHostAndPort | false | false | false | Boolean | Specifies whether to force the addition of scheme, host and port or not |
href | false | false | String | The URL. | |
id | false | false | String | HTML id attribute | |
includeContext | false | true | false | Boolean | Whether actual context should be included in URL |
includeParams | false | none | false | String | The includeParams attribute may have the value 'none', 'get' or 'all' |
javascriptTooltip | false | false | false | Boolean | Use JavaScript to generate tooltips |
key | false | false | String | Set the key (name, value, label) for this particular component | |
label | false | false | String | Label expression used for rendering an element specific label | |
labelSeparator | false | : | false | String | String that will be appended to the label |
labelposition | false | false | String | Define label position of form element (top/left) | |
method | false | false | String | The method of action to use | |
name | false | false | String | The name to set for element | |
namespace | false | false | String | The namespace to use | |
onblur | false | false | String | Set the html onblur attribute on rendered html element | |
onchange | false | false | String | Set the html onchange attribute on rendered html element | |
onclick | false | false | String | Set the html onclick attribute on rendered html element | |
ondblclick | false | false | String | Set the html ondblclick attribute on rendered html element | |
onfocus | false | false | String | Set the html onfocus attribute on rendered html element | |
onkeydown | false | false | String | Set the html onkeydown attribute on rendered html element | |
onkeypress | false | false | String | Set the html onkeypress attribute on rendered html element | |
onkeyup | false | false | String | Set the html onkeyup attribute on rendered html element | |
onmousedown | false | false | String | Set the html onmousedown attribute on rendered html element | |
onmousemove | false | false | String | Set the html onmousemove attribute on rendered html element | |
onmouseout | false | false | String | Set the html onmouseout attribute on rendered html element | |
onmouseover | false | false | String | Set the html onmouseover attribute on rendered html element | |
onmouseup | false | false | String | Set the html onmouseup attribute on rendered html element | |
onselect | false | false | String | Set the html onselect attribute on rendered html element | |
openTemplate | false | false | String | Set template to use for opening the rendered html. | |
portletMode | false | false | String | The resulting portlet mode | |
portletUrlType | false | false | String | Specifies if this should be a portlet render or action URL. Default is "render". To create an action URL, use "action". | |
required | false | false | false | Boolean | If set to true, the rendered element will indicate that input is required |
requiredposition | false | false | String | Define required position of required form element (left|right) | |
scheme | false | false | String | Set scheme attribute | |
tabindex | false | false | String | Set the html tabindex attribute on rendered html element | |
template | false | false | String | The template (other than default) to use for rendering the element | |
templateDir | false | false | String | The template directory. | |
theme | false | false | String | The theme (other than default) to use for rendering the element | |
title | false | false | String | Set the html title attribute on rendered html element | |
tooltip | false | false | String | Set the tooltip of this particular component | |
tooltipConfig | false | false | String | Deprecated. Use individual tooltip configuration attributes instead. | |
tooltipCssClass | false | StrutsTTClassic | false | String | CSS class applied to JavaScrip tooltips |
tooltipDelay | false | Classic | false | String | Delay in milliseconds, before showing JavaScript tooltips |
tooltipIconPath | false | false | String | Icon path used for image that will have the tooltip | |
value | false | false | String | The target value to use, if not using action | |
windowState | false | false | String | The resulting portlet window state |
Usage
To get started, use the head tag and the ajax theme. See ajax head template for more information. Then look at the usage details for the ajax a template.
If you want to use additional parameters in your s:a the best practice is to use a s:url to create your url and then leverage this url into your s:a tag. This is done by creating a s:url and specifying an id attribute.. like "testUrlId" in this example. Then in the s:a tag reference this id in the href attribute via " %{testUrlId}"
<s:a> 和 <s:url> 标签
这两个标签用来创建一个URL 链接。所谓URL 连接,即是Web 中最常见的标签样式:
<a href=""> 标签文本</a>
但在Struts 2 中,Struts 对其做了封装,使用<s:url> 和<s:a> 来表示<a> 标签,经过Java Web 服务器的解析,客户端最终看到的还是<a> 标签。
其中<s:a> 标签支持<s:url> 标签的所有属性,包括使用<param> 来嵌套属性参数。但是如果你想在<s:a> 中添加额外的参数,这里建议使用<s:url> 来创建你的url 。然后你再将这个url 插入到<s:a> 标签中。
<s:url var="testUrlId" namespace="/subscriber" action="customField" method="delete">
<s:param name="customFieldDefinition.id" value="${id}"/>
</s:url>
<s:a errorText="Sorry your request had an error." preInvokeJS="confirm('Are you sure you want to delete this item?')" href="%{testUrlId}">
<img src="<s:url value="/images/delete.gif"/>" border="none"/>
</s:a>
<img xsrc="<s:url value="/images/delete.gif"/>" border="none"/><s:a><img xsrc="<s:url value="/images/delete.gif"/>" border="none"/></s:a>
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
The id attribute is deprecated in Struts 2.1.x, and has been replaced by the var attribute. |
The property struts.url.includeParams can be used to set the default value of the includeParams attribute.
Setting the default value of includeParams
<struts>
...
<constant name="struts.url.includeParams" value="none" />
...
</struts>
See Constant Configuration for further information.
As of Struts 2.1.3 the includeParams constant defaults to "none". |
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
action | false | false | String | The action to generate the URL for, if not using value 指定url地址为哪个action,如果没有,就用value作为url的值。 | |
anchor | false | false | String | The anchor for this URL指定URL的锚点 | |
encode | false | true | false | Boolean | Whether to encode parameters是否对参数编码 |
escapeAmp | false | true | false | Boolean | Specifies whether to escape ampersand (&) to (& or not指定是否对&进行编码 |
forceAddSchemeHostAndPort | false | false | false | Boolean | Specifies whether to force the addition of scheme, host and port or not |
id | false | false | String | Deprecated. Use 'var' instead | |
includeContext | false | true | false | Boolean | Whether actual context should be included in URL |
includeParams | false | none | false | String | The includeParams attribute may have the value 'none', 'get' or 'all' 指定是否包含请求参数。 |
method | false | false | String | The method of action to use | |
namespace | false | false | String | The namespace to use | |
portletMode | false | false | String | The resulting portlet mode | |
portletUrlType | false | false | String | Specifies if this should be a portlet render or action URL. Default is "render". To create an action URL, use "action". | |
scheme | false | false | String | Set scheme attribute | |
value | false | false | String | The target value to use, if not using action | |
var | false | false | String | Name used to reference the value pushed into the Value Stack 如果使用,就会把链接值放进value stack中 | |
windowState | false | false | String | The resulting portlet window state |
Description
This tag is used to create a URL.
这个标签是用来创建一个URL地址。
You can use the <param> tag inside the body to provide additional request parameters. If the value of a param is an Array or an Iterable all the values will be added to the URL.
你能使用<param> tag向指定的URl发送请求参数。如果参数值是一个数组或者是一个iterator,所有的值都会被添加到URl中
NOTE:
By default request parameters will be separated using escaped ampersands (i.e., &. This is necessary for XHTML compliance, however, when using the URL generated by this tag with the <s:property> tag, the escapeAmp attribute should be used to disable ampersand escaping.
NOTE:
When includeParams is 'all' or 'get', the parameter defined in a <param> tag will take precedence over any params included due to the includeParams attribute. For example, in Example 3 below, if there is a id parameter in the url where the page this tag is included like http://<host>:<port>/<context>/editUser.action?id=3333&name=John the generated url will be http://<host>:<port>/<context>/editUser.action?id=22&name=John because the parameter defined in the param tag will take precedence.
当属性 includeParams的值 是' all' 或' get' ,在<PARAM> 标记中定义的 参数将 优先于 任何 参数 ,包括 includeParams 属性。例如,在 示例 3 所示:
如果 有一个 id 参数的 url 如这个标签 这样:
http://<host>:<port>/<context>/editUser.action?id=3333&name=John
生成的URL 将是
http://<host>:<port>/<context>/editUser.action?id=22&name=John ,
因为在param 标签中定义的 参数将 优先考虑 。
Examples
<-- Example 1 -->
<s:url value="editGadget.action">
<s:param name="id" value="%{selected}" />
</s:url>
<-- Example 2 -->
<s:url action="editGadget">
<s:param name="id" value="%{selected}" />
</s:url>
<-- Example 3-->
<s:url includeParams="get">
<s:param name="id" value="%{'22'}" />
</s:url>
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
This tag enables developers to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified.
Parameters can be passed to the action using nested param tags.
这个标记使开发人员直接通过指定的动作名称(action name)和可选的命名空间(optional namespace)从一个JSP页面来调用动作(actions)。
标签的参数可以通过param标签来传递到action中
Placement in context
The action will not be published to the context until the whole tag is evaluated, meaning that inside the body of the tag, the action cannot be accessed, For example:
这里需要注意的是:在<action>标签内部,action是不允许被访问的
<s:action var="myAction" name="MyAction" namespace="/">
Is "myAction" null inside the tag? <s:property value="#myAction == null" />
</s:action>
Is "myAction" null outside the tag? <s:property value="#myAction == null" />
Will print:
Is "myAction" null inside the tag? true
Is "myAction" null outside the tag? false
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
executeResult | false | false | false | Boolean | Whether the result of this action (probably a view) should be executed/rendered指定是否将Action的处理结果包含到本页面中.默认值为false,不包含 |
flush | false | true | false | Boolean | Whether the writer should be flush upon end of action component tag, default to true |
id | false | false | String | Deprecated. Use 'var' instead | |
ignoreContextParams | false | false | false | Boolean | Whether the request parameters are to be included when the action is invoked 可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数 |
name | true | false | String | Name of the action to be executed (without the extension suffix eg. .action) | |
namespace | false | namespace from where tag is used | false | String | Namespace for action to call |
rethrowException | false | false | false | Boolean | Whether an exception should be rethrown, if the target action throws an exception |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
Examples
public class ActionTagAction extends ActionSupport {
public String execute() throws Exception {
return "done";
}
public String doDefault() throws Exception {
ServletActionContext.getRequest().setAttribute("stringByAction", "This is a String put in by the action's doDefault()");
return "done";
}
}
<xwork>
....
<action name="actionTagAction1" class="tmjee.testing.ActionTagAction">
<result name="done">success.jsp</result>
</action>
<action name="actionTagAction2" class="tmjee.testing.ActionTagAction" method="default">
<result name="done">success.jsp</result>
</action>
....
</xwork>
<div>The following action tag will execute result and include it in this page</div>
<br />
<s:action name="actionTagAction" executeResult="true" />
<br />
<div>The following action tag will do the same as above, but invokes method specialMethod in action</div>
<br />
<s:action name="actionTagAction!specialMethod" executeResult="true" />
<br />
<div>The following action tag will not execute result, but put a String in request scope
under an id "stringByAction" which will be retrieved using property tag</div>
<s:action name="actionTagAction!default" executeResult="false" />
<s:property value="#attr.stringByAction" />
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Instantiates a class that conforms to the JavaBeans specification. This tag has a body which can contain a number of Param elements to set any mutator methods on that class.
If the var attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.
Bean标签,当然需要一个JavaBean。它的属性值的操作是经由Bean标签中的参数属性来进行赋值。当然,它还有一个id属性可以进行赋值,这样就可以在上下文中使用这个Bean如果在BeanTag中设置了var属性值,那么它将把实例化后的bean放入到stack's Context中。
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
id | false | false | String | Deprecated. Use 'var' instead | |
name | true | false | String | The class name of the bean to be instantiated (must respect JavaBean specification) | |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
Examples
<-- in freemarker form -->
[@s.bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter"]
[s:param name="foo" value="BAR"/]
The value of foo is : [s:property value="foo"/], when inside the bean tag.<br />
[/s:bean]
<-- in jsp form -->
<s:bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter">
<s:param name="foo" value="BAR" />
The value of foot is : <s:property value="foo"/>, when inside the bean tag <br />
</s:bean>
This example instantiates a bean called SimpleCounter and sets the foo property (setFoo('BAR')). The SimpleCounter object is then pushed onto the Valuestack, which means that we can call its accessor methods (getFoo()) with the Property tag and get their values.
这个例子实例化了一个名叫SimpleCounter的bean,并设置foo属性(setFoo(‘BAR’))。然后将SimpleCounter对象压入值栈(Valuestack)中,这意味着我们可以调用property tag的访问方法(getFoo())来得到它的值。
在上面的例子中,id的属性值已经设为counter,这意味着SimpleCounter对象压入值栈(Valuestack)后可以通过如下标签来访问它:
In the above example, the id has been set to a value of counter. This means that the SimpleCounter class will be placed into the stack's context. You can access the SimpleCounter class using a Struts tag:
<-- jsp form --> <s:property value="#counter" /><-- freemarker form --> [s:property value="#counter.foo"/]
In the property tag example, the # tells Ognl to search the context for the SimpleCounter class which has an id(key) of counter
Description
Format Date object in different ways.
The date tag will allow you to format a Date in a quick and easy way. You can specify a custom format (eg. "dd/MM/yyyy hh:mm"), you can generate easy readable notations (like "in 2 hours, 14 minutes"), or you can just fall back on a predefined format with key 'struts.date.format' in your properties file.
If that key is not defined, it will finally fall back to the default DateFormat.MEDIUM formatting.
Note: If the requested Date object isn't found on the stack, a blank will be returned.
以不同的方式格式化日期对象。
<s:date>标记允许你以一个快速简便的方式格式化一个日期,你可以自定义日期的格式(eg. "dd/MM/yyyy hh:mm")。你也可以将日期转化成一个易读的记(like"in2hours,14minutes"),
或者你可以仅仅依靠在属性文件中预定义的”struts.date.format”的key来格式化日期。
Note: 如果请求的日期对象在堆栈找不到,那么将返回空白。
Configurable attributes are :-
- name
- nice
- format
Following how the date component will work, depending on the value of nice attribute (which by default is false) and the format attribute.
Condition 1: With nice attribute as true
i18n key | default |
struts.date.format.past | {0} ago |
struts.date.format.future | in {0} |
struts.date.format.seconds | an instant |
struts.date.format.minutes | {0,choice,1#one minute|1<{0} minutes} |
struts.date.format.hours | {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1<, {1} minutes} |
struts.date.format.days | {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours} |
struts.date.format.years | {0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one day|1<, {1} days} |
Condition 2: With nice attribute as false and format attribute is specified eg. dd/MM/yyyyy
In this case the format attribute will be used.
Condition 3: With nice attribute as false and no format attribute is specified
i18n key | default |
struts.date.format | if one is not found DateFormat.MEDIUM format will be used |
通常,nice属性和format属性不同时指定,(不指定nice属性时,该属性值为false)。因为指定nice为true,代表输出指定日期和当前时刻的时差;指定format属性,则表明将指定日期按format指定的格式来个格式化输出。
如果即没有指定format,也没指定nice=“true”,则系统会到国际化资源文件中寻找key为struts.date.format的消息,将该消息当成格式化文本来格式化日期。如果无法找到key为struts.date.format的消息,则默认采用DateFormat.MEDIUM格式输出
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
format | false | false | String | Date or DateTime format pattern | |
id | false | false | String | Deprecated. Use 'var' instead | |
name | true | false | String | The date value to format | |
nice | false | false | false | Boolean | Whether to print out the date nicely 用于指定是否输出指定日期和当前时刻的时差。默认是false,即不输出 |
timezone | false | false | String | The specific timezone in which to format the date | |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
<s:date name="person.birthday" format="dd/MM/yyyy" />
<s:date name="person.birthday" format="%{getText('some.i18n.key')}" />
<s:date name="person.birthday" nice="true" />
<s:date name="person.birthday" />
<s:debug>
这个学过struts的地球人都知道:
输出值栈中的内容
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Gets a resource bundle and place it on the value stack. This allows the text tag to access messages from any bundle, and not just the bundle associated with the current action.
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
name | true | String | false | String | Name of resource bundle to use (eg foo/bar/customBundle) |
Examples
<s:i18n name="myCustomBundle">
The i18n value for key aaa.bbb.ccc in myCustomBundle is <s:property value="text('aaa.bbb.ccc')" />
</s:i18n>
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Include a servlet's output (result of servlet or a JSP page).
Note: Any additional params supplied to the included page are not accessible within the rendered page through the <s:property...> tag since no valuestack will be created. You can, however, access them in a servlet via the HttpServletRequest object or from a JSP page via a scriptlet.
包含一个servlet的输入(servlet或JSP页面的结果)。
Note: 你不能通过<s:property...>来访问所包含页面的任何属性,因为没有值(valuestack)会被创建。然而,你可以通过HttpServletRequest对象在一个servlet中来访问它们,或者是通过scriptlet在jsp页面上访问它们。
How To access parameters Parameters are passed as request parameters, so use the ${param.ParamName} notation to access them. Do not use the property tag to access parameters in included files. 参数作为request参数被传递,因此可以使用$ {param.ParamName}标记来访问它们。不要使用<s:property...>标记来访问包含文件的参数。 |
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
value | true | false | String | The jsp/servlet output to include |
Example
<-- One: -->
<s:include value="myJsp.jsp" />
<-- Two: -->
<s:include value="myJsp.jsp">
<s:param name="param1" value="value2" />
<s:param name="param2" value="value2" />
</s:include>
<-- Three: -->
<s:include value="myJsp.jsp">
<s:param name="param1">value1</s:param>
<s:param name="param2">value2</s:param>
</s:include>
Example one - do an include myJsp.jsp page
Example two - do an include to myJsp.jsp page with parameters param1=value1 and param2=value2
Example three - do an include to myJsp.jsp page with parameters param1=value1 and param2=value2
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
This tag can be used to parameterize other tags.
The include tag and bean tag are examples of such tags.The parameters can be added with or without a name as key. If the tag provides a name attribute the parameters are added using the {@link Component#addParameter(String, Object) addParamter} method. For unnamed parameters the Tag must implement the UnnamedParametric interface defined in this class (e.g. The TextTag does this).
This tag has the following two paramters.
- name (String) - the name of the parameter
- value (Object) - the value of the parameter
Note: When you declare the param tag, the value can be defined in either a value attribute or as text between the start and end tag. Struts behaves a bit different according to these two situations. This is best illustrated using an example:
<param name="color">blue</param> <-- (A) -->
<param name="color" value="blue"/> <-- (B) -->
In the first situation (A) the value would be evaluated to the stack as a java.lang.String object. And in situation (B) the value would be evaluated to the stack as a java.lang.Object object.
For more information see WW-808.
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
name | false | false | String | Name of Parameter to set | |
value | false | The value of evaluating provided name against stack | false | String | Value expression for Parameter to set |
Examples
<pre>
<ui:component>
<ui:param name="key" value="[0]"/>
<ui:param name="value" value="[1]"/>
<ui:param name="context" value="[2]"/>
</ui:component>
</pre>
where the key will be the identifier and the value the result of an OGNL expression run against the current ValueStack.
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Used to get the property of a value, which will default to the top of the stack if none is specified.
用于获取一个属性的值。Property顾名思义,可以与<s:bean>标签结合使用,一个是给bean赋值,一个是从bean中读取值。
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
default | false | false | String | The default value to be used if value attribute is null | |
escape | false | true | false | Boolean | Deprecated. Use 'escapeHtml'. Whether to escape HTML |
escapeCsv | false | false | false | Boolean | Whether to escape CSV (useful to escape a value for a column) |
escapeHtml | false | true | false | Boolean | Whether to escape HTML |
escapeJavaScript | false | false | false | Boolean | Whether to escape Javascript |
escapeXml | false | false | false | Boolean | Whether to escape XML |
value | false | <top of stack> | false | Object | Value to be displayed |
Examples
<s:push value="myBean">
<!-- Example 1: -->
<s:property value="myBeanProperty" />
<!-- Example 2: -->TextUtils
<s:property value="myBeanProperty" default="a default value" />
</s:push>
Example 1 prints the result of myBean's getMyBeanProperty() method.
Example 2 prints the result of myBean's getMyBeanProperty() method and if it is null, print 'a default value' instead.
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Push value on stack for simplified usage.
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
value | true | false | String | Value to push on stack |
Examples
<s:push value="user">
<s:propery value="firstName" />
<s:propery value="lastName" />
</s:push>
Pushed user into the stack, and hence property tag could access user's properties
(firstName, lastName etc) since user is not at the top of the stack
<s:push value="myObject"> ----- (1)
<s:bean name="jp.SomeBean" var="myBean"/> ----- (2)
<s:param name="myParam" value="top"/> ----- (3)
</s:bean>
</s:push>
when in (1), myObject is at the top of the stack
when in (2), jp.SomeBean is in the top of stack, also in stack's context with key myBean
when in (3), top will get the jp.SomeBean instance
<s:push value="myObject"> ---(A)
<s:bean name="jp.SomeBean" var="myBean"/> ---(B)
<s:param name="myParam" value="top.mySomeOtherValue"/> ---(C)
</s:bean>
</s:push>
when in (A), myObject is at the top of the stack
when in (B), jp.SomeBean is at the top of the stack, also in context with key myBean
when in (C), top refers to jp.SomeBean instance. so top.mySomeOtherValue would invoke SomeBean's mySomeOtherValue() method
<s:push value="myObject"> ---- (i)
<s:bean name="jp.SomeBean" var="myBean"/> ---- (ii)
<s:param name="myParam" value="[1].top"/> -----(iii)
</s:bean>
</s:push>
when in (i), myObject is at the top of the stack
when in (ii), jp.SomeBean is at the top of the stack, followed by myObject
when in (iii), [1].top will returned top of the cut of stack starting from myObject, namely myObject itself
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
The set tag assigns a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. This is useful in both cases: when the complex expression takes time (performance improvement) or is hard to read (code readability improvement).
Set标签比较简单。Set标签用户将某一值赋给某一变量,因此,任何对该项值的引用都可以通过该变量来得到该值。该变量的活动范围可自定义。如下例中,定义一健/值对,对值的引用,直接引用值就可以
If the tag is used with body content, the evaluation of the value parameter is omitted. Instead, the String to which the body eveluates is set as value for the scoped variable.
The scopes available are as follows :-
- application - the value will be set in application scope according to servlet spec. using the name as its key
- session - the value will be set in session scope according to servlet spec. using the name as key
- request - the value will be set in request scope according to servlet spec. using the name as key
- page - the value will be set in page scope according to servlet sepc. using the name as key
- action - the value will be set in the request scope and Struts' action context using the name as key
NOTE:
If no scope is specified, it will default to action scope.
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
id | false | false | String | Deprecated. Use 'var' instead | |
name | false | false | String | Deprecated. Use 'var' instead | |
scope | false | action | false | String | The scope in which to assign the variable. Can be application, session, request, page, or action. |
value | false | false | String | The value that is assigned to the variable named name | |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
Examples
s:set name="personName" value="person.name"/>
Hello, <s:property value="#personName"/>. How are you?
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
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.
For more details on using resource bundles with Struts 2 read the localization guide.
Parameters
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
id | false | false | String | Deprecated. Use 'var' instead | |
name | true | false | String | Name of resource property to fetch | |
searchValueStack | false | true | false | Boolean | Search the stack if property is not found on resources |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
Examples
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.</p>
<!-- 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>
Other example
<s:text name="format.money"><s:param name="value" value="myMoneyValue"/></s:text>
where the following is in a regular (possibly locale-specific) properties file:
format.money={0,number,currency}
For more about formatting text, see
- http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html
- http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html
If you wish to use i18n in your tag attributes
This will not work:
<s:textfield name="lastName" label="<s:text name="person.lastName"/>" ../>
Instead, you should use the getText() method that you inherit when your Action extends XWork's ActionSupport:
<s:textfield name="lastName" label="getText('person.lastName')" ../>