Magazine
 
Struts2 Tags

evaluates to ‘false’ and <s:elseif > tag evaluates to ‘true’ then the body of the <s:elseif > tag is processed. If the condition in <s:if > tag and <s:elseif > tags evaluates to ‘false’ then only the <s:else > tag is processed.

IfControlTag.jsp

<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Struts 2 if/elseif/else Control Tag
Example</title>
</head>
<body>
<s:set name=”technologyName”
value=”%{‘Java’}”/>
<s:if
test=”%{#technologyName==’Java’}”>
<div><s:property
value=”%{#technologyName}” /></div>
</s:if>
<s:elseif
test=”%{#technologyName==’Jav’}”>
<div><s:property
value=”%{#technologyName}” /></div>
</s:elseif>
<s:else>
<div>Technology Value is not Java</
div>
</s:else>
</body>
</html>

In the IfControlTag.jsp only <s:if> tag evaluates to true, we get the output equal to “Java”.
Output:

 

 

2. Append Tag (Control Tags) Example
The append tag is a generic tag that is used to merge multiple iterators into one iterator. Append Iterator tag is used to append iterators to form an appended iterator through which the entries goes from one iterator to another after each respective iterator is exhausted of entries. Create two lists in the action class and populate them with various items as shown in the“AppendTag” class.

AppendTag.java

package net.javajazzup;
import
com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class AppendTag extends
ActionSupport{
private List list1;
private List list2;
public String execute()throws Exception{
list1 = new ArrayList();
list1.add(“JAVA”);
list1.add(“HTML”);
list1.add(“CSS”);
list1.add(“AJAX”);
list1.add(“JAVA SCRIPT”);
list2 = new ArrayList();
list2.add(“Soft. Engg.”);
list2.add(“Sr. Soft. Engg.”);
list2.add(“Team Leader”);
list2.add(“Project Manager”);

Dec 2007 | Java Jazz Up | 42
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF