Reputation: 69
I am migrating my application from Struts-1 to Struts-2.
The following piece of code uses Struts-1 iterate tag to iterate over a collection "myFormBeanCollection".
Here myFormBean is the form bean, myFormBeanCollection is one property of myFormBean and is of type ArrayList, this list holds the objects of type "com.xyz.SomeClass".
And next comes a scriptlet element, and then some bean:write...
In scriptlet code: getDate() method is defined in "com.xyz.SomeClass".
<logic:iterate name="myFormBean" property= "myFormBeanCollection" id="someId" type="com.xyz.SomeClass">
<%
String startDate = dateFormat.format(someId.getDate());
%>
<td width="13%" align="center">
<%=startDate%>
</td>
<td width="8%" align="center">
<bean:write name="someId" property="prop_1" />
</td>
</logic:iterate>
How can I migrate this particular code to Struts-2.
I tried using Struts2 iterator tag.
But couldn't succeed in writing the scriptlet. Not sure on how to call "getDate()" method in the scriptlet as how it was done in above code(Struts-1).
<s:iterator value="myFormBean.myFormBeanCollection">
<%
String startDate = dateFormat.format(""); // Not sure on how to call "getDate()" method as how it was done in above code(Struts-1).
%>
<s:property value="countryName" />,
</s:iterator>
Any help would be greatly appreciated.
Thanks, Sunil
Upvotes: 0
Views: 389
Reputation: 160191
You wou'dn't, you'd use the <s:date />
tag:
<s:date name="date" format="whatever" />
In fairness, you didn't need to use scriptlet in the original version either--the less work you do in Java in JSP the better: stick to HTML and tags only.
Instead of blindly re-writing the exact same way try to make structural and technical improvements.
Upvotes: 0