Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Struts2 data label


May 15, 2021 Struts2


Table of contents


Struts2's data labels are primarily used for data displayed on the action page. T he main data labels are listed below:

Action tag

This label allows developers to call action directly from the JSP page by specifying the action name and optional namespace. T he body content of the label is used to render the results of the action. A ny result handlers .xml this action in the struts will be ignored unless the executeResult parameter is specified.

<div>Tag to execute the action</div>
<br />
<s:action name="actionTagAction" executeResult="true" />
<br />
<div>To invokes special method  in action class</div>
<br />
<s:action name="actionTagAction!specialMethod" executeResult="true" />

Review the detailed examples

include label

These include tags will be used to include a JSP file on another JSP page.

<-- First Syntax -->
<s:include value="myJsp.jsp" />

<-- Second Syntax -->
<s:include value="myJsp.jsp">
   <s:param name="param1" value="value2" />
   <s:param name="param2" value="value2" />
</s:include>

<-- Third Syntax -->
<s:include value="myJsp.jsp">
   <s:param name="param1">value1</s:param>
   <s:param name="param2">value2</s:param>
</s:include>

Review the detailed examples

bean label

These bean tags instantiate a class that conforms to the Java Beans specification. T his label has a body that can contain some Param elements to set up any mutator method. I f the var property is set on the BeanTag, it puts the instantiated bean in the Context of the value stack.

<s:bean name="org.apache.struts2.util.Counter" var="counter">
   <s:param name="first" value="20"/>
   <s:param name="last" value="25" />
</s:bean>

Review the detailed examples

Date label

The data label allows the date to be formatted in a quick and easy way. Users can specify a custom date format (e.g. "dd/MM/yyyy hh:mm"), generate easy-to-read symbols (e.g., "in 2 hours and 14 minutes"), or return to a predefined format using key: "struts.date.format" in the property file.

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

Review the detailed examples

param label

These param labels can be used to parameterize other labels. T his label has the following two parameters.

  • name (string) - the name of the argument

  • value (object) - the value of the argument

<pre>
<ui:component>
 <ui:param name="key"     value="[0]"/>
 <ui:param name="value"   value="[1]"/>
 <ui:param name="context" value="[2]"/>
</ui:component>
</pre>

Review the detailed examples

property label

These property tags are used to get a value of the property, which, if not specified, defaults to the top of the value stack.

<s:push value="myBean">
    <!-- Example 1: -->
    <s:property value="myBeanProperty" />

    <!-- Example 2: -->TextUtils
    <s:property value="myBeanProperty" default="a default value" />
</s:push>

Review the detailed examples

Push label:

These push labels are used to push values in the stack to simplify use.

<s:push value="user">
    <s:propery value="firstName" />
    <s:propery value="lastName" />
</s:push>

Review the detailed examples

Set label

These set labels assign values to variables within the specified range. I t is useful when you want to assign a variable to a complex expression and then refer only to it instead of a complex expression. T he range of applications that can be applied is applications, sessions, requests, pages, and action.

<s:set name="myenv" value="environment.name"/>
<s:property value="myenv"/>

Review the detailed examples

Text label

These text tags are used to render I18n text messages.

<!-- 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>

Review the detailed examples

url tag

These url tags are used to create URLs.

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

Review the detailed examples