Struts 2 Tags
<%@taglib prefix="s" uri="/struts-tags"%>
<h3></h3>
<h3> Conditionals </h3>
<s:if test='name=="abc"'>
you are <s:property value="name"/>
</s:if>
<s:else>
you are not abc
</s:else>
<h3>collections and Iteration(ArrayList) </h3>
<ul>
<s:iterator value="books" var="book">
<li><s:property value="book"/></li>
</s:iterator>
</ul>
<h3>collections and Iteration (Map)</h3>
<ul>
<s:iterator value="emails">
<li><s:property value="key"/> : <s:property value="value"/></li>
</s:iterator>
</ul>
<ul>
<s:iterator value="emails" var="item">
<li><s:property value="#item.key"/> : <s:property value="#item.value"/></li>
</s:iterator>
</ul>
<h3>tracking iteration status </h3>
<ul>
<s:iterator value="books" var="book" status="stat">
<li>
<s:property value="#stat.index"/>:
<s:property value="#stat.count"/>:
<s:property value="#stat.even"/>:
<s:property value="#stat.odd"/>:
<s:property value="#stat.first"/>:
<s:property value="#stat.last"/>:
<s:property value="#stat.modulus(2)"/>:
<s:property value="#stat.modulus(4)"/>:
<s:property value="#stat.count%4"/>:
<s:property value="book"/>
</li>
</s:iterator>
</ul>
<h3> s:generator : it is used to create a list in value stack</h3>
<s:generator val="'1,2,3,4,5'" separator=",">
<ul>
<s:iterator>
<li><s:property/></li>
</s:iterator>
</ul>
</s:generator>
<h3> here we can create a variavle that poits the list generated by generator</h3>
<s:generator val="'1,2,3,4,5'" separator="," var="mylist"/>
<h3> now we can use it anywhere</h3>
<ul>
<s:iterator value="mylist">
<li><s:property/></li>
</s:iterator>
</ul>
<h3> After full iteration we can not use mylist itarator again
we need to generate new list</h3>
<h3> Using convertor in generator.
get a object from action class that implements IteratorGenerator.Converter </h3>
<s:generator val="'1,2,3,4,5,6,7,8,9,0'" separator="," var="mylist" converter="digitConverter"/>
<ul>
<s:iterator value="mylist">
<li><s:property/></li>
</s:iterator>
</ul>
<h3>s:append </h3>
<s:append var="appended">
<s:param value="{1,2,3,4}"/>
<s:param value="{'a','b','c','d'}"/>
</s:append>
<s:iterator value="appended">
<s:property/>
</s:iterator>
<h3>s:merge</h3>
<s:merge var="merged">
<s:param value="{1,2,3,4}"/>
<s:param value="{'a','b','c','d'}"/>
</s:merge>
<s:iterator value="merged">
<s:property/>
</s:iterator>
<h3>s:subset - use to get iterate on portion of items from collection</h3>
<!--data from books property of action -->
<s:subset source='books' start="2" count="2">
<s:iterator>
<s:property/>
</s:iterator>
</s:subset>
<%--<s:debug/>--%>
Output
<%@taglib prefix="s" uri="/struts-tags"%>
<h3></h3>
<h3> Conditionals </h3>
<s:if test='name=="abc"'>
you are <s:property value="name"/>
</s:if>
<s:else>
you are not abc
</s:else>
<h3>collections and Iteration(ArrayList) </h3>
<ul>
<s:iterator value="books" var="book">
<li><s:property value="book"/></li>
</s:iterator>
</ul>
<h3>collections and Iteration (Map)</h3>
<ul>
<s:iterator value="emails">
<li><s:property value="key"/> : <s:property value="value"/></li>
</s:iterator>
</ul>
<ul>
<s:iterator value="emails" var="item">
<li><s:property value="#item.key"/> : <s:property value="#item.value"/></li>
</s:iterator>
</ul>
<h3>tracking iteration status </h3>
<ul>
<s:iterator value="books" var="book" status="stat">
<li>
<s:property value="#stat.index"/>:
<s:property value="#stat.count"/>:
<s:property value="#stat.even"/>:
<s:property value="#stat.odd"/>:
<s:property value="#stat.first"/>:
<s:property value="#stat.last"/>:
<s:property value="#stat.modulus(2)"/>:
<s:property value="#stat.modulus(4)"/>:
<s:property value="#stat.count%4"/>:
<s:property value="book"/>
</li>
</s:iterator>
</ul>
<h3> s:generator : it is used to create a list in value stack</h3>
<s:generator val="'1,2,3,4,5'" separator=",">
<ul>
<s:iterator>
<li><s:property/></li>
</s:iterator>
</ul>
</s:generator>
<h3> here we can create a variavle that poits the list generated by generator</h3>
<s:generator val="'1,2,3,4,5'" separator="," var="mylist"/>
<h3> now we can use it anywhere</h3>
<ul>
<s:iterator value="mylist">
<li><s:property/></li>
</s:iterator>
</ul>
<h3> After full iteration we can not use mylist itarator again
we need to generate new list</h3>
<h3> Using convertor in generator.
get a object from action class that implements IteratorGenerator.Converter </h3>
<s:generator val="'1,2,3,4,5,6,7,8,9,0'" separator="," var="mylist" converter="digitConverter"/>
<ul>
<s:iterator value="mylist">
<li><s:property/></li>
</s:iterator>
</ul>
<h3>s:append </h3>
<s:append var="appended">
<s:param value="{1,2,3,4}"/>
<s:param value="{'a','b','c','d'}"/>
</s:append>
<s:iterator value="appended">
<s:property/>
</s:iterator>
<h3>s:merge</h3>
<s:merge var="merged">
<s:param value="{1,2,3,4}"/>
<s:param value="{'a','b','c','d'}"/>
</s:merge>
<s:iterator value="merged">
<s:property/>
</s:iterator>
<h3>s:subset - use to get iterate on portion of items from collection</h3>
<!--data from books property of action -->
<s:subset source='books' start="2" count="2">
<s:iterator>
<s:property/>
</s:iterator>
</s:subset>
<%--<s:debug/>--%>
Output
Conditionals
you are not abccollections and Iteration(ArrayList)
- Java
- J2EE
- JSP
- Servlet
- C
- C++
collections and Iteration (Map)
- abc : abc@gmail.com
- xyz : xyz@yahoo.com
- bbc : bbc@gjh.com
- abc : abc@gmail.com
- xyz : xyz@yahoo.com
- bbc : bbc@gjh.com
tracking iteration status
- 0: 1: false: true: true: false: 1: 1: 1: Java
- 1: 2: true: false: false: false: 0: 2: 2: J2EE
- 2: 3: false: true: false: false: 1: 3: 3: JSP
- 3: 4: true: false: false: false: 0: 0: 0: Servlet
- 4: 5: false: true: false: false: 1: 1: 1: C
- 5: 6: true: false: false: true: 0: 2: 2: C++
s:generator : it is used to create a list in value stack
- 1
- 2
- 3
- 4
- 5
here we can create a variavle that poits the list generated by generator
now we can use it anywhere
- 1
- 2
- 3
- 4
- 5
After full iteration we can not use mylist itarator again we need to generate new list
Using convertor in generator. get a object from action class that implements IteratorGenerator.Converter
- one
- two
- three
- four
- five
- six
- seven
- eight
- nine
- zero
Comments