
My result is in arraylist and i want to display it in table form using iterator tag

Struts 2 Iterator tag is used to iterate over a value, which can be any of java.util.Collection or java.util.Iterator.
1)IteratorAction.java:
package com.roseindia.common.action
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
public class IteratorAction extends ActionSupport{
private List<String> comboMeals;
public List<String> getComboMeals() {
return comboMeals;
}
public void setComboMeals(List<String> comboMeals) {
this.comboMeals = comboMeals;
}
public String execute() {
comboMeals = new ArrayList<String>();
comboMeals.add("Snack Plate");
comboMeals.add("Dinner Plate");
comboMeals.add("Colonel Chicken Rice Combo");
comboMeals.add("Colonel Burger");
comboMeals.add("O.R. Fillet Burger");
comboMeals.add("Zinger Burger");
return SUCCESS;
}
}
2)iterator.jsp:
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body>
<h1>Struts 2 Iterator tag example</h1>
<h3>Simple Iterator</h3>
<ol>
<s:iterator value="comboMeals">
<li><s:property /></li>
</s:iterator>
</ol>
<h3>Iterator with IteratorStatus</h3>
<table>
<s:iterator value="comboMeals" status="comboMealsStatus">
<tr>
<s:if test="#comboMealsStatus.even == true">
<td style="background: #CCCCCC"><s:property/></td>
</s:if>
<s:elseif test="#comboMealsStatus.first == true">
<td><s:property/> (This is first value) </td>
</s:elseif>
<s:else>
<td><s:property/></td>
</s:else>
</tr>
</s:iterator>
</table>
</body>
</html>
3)struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="iteratorAction"
class="com.roseindia.common.action.IteratorAction" >
<result name="success">pages/iterator.jsp</result>
</action>
</package>
</struts>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.