Struggling with struts iterator tag and Object[] array
Problem summary
I have fixed this problem now so I am happy, but I wasn't while trying to figure it out. I tried quite a lot of things and this was the first one that worked.
I was using Hibernate and the HSQL was:
SELECT weblogentry.summary , weblogentry.pubtime , rolleruser.username
FROM Weblogentry weblogentry, Rolleruser rolleruser
WHERE weblogentry.userid = rolleruser.id AND weblogentry.publishentry = 1
That is really pretty irrelevant as this post is about iterating over an Object[] with each Object containing objects of type [String , java.sql.date , String]. I had problems in representing this on my JSP which used Struts2 tags.
I tried a few things including single, double and triple nested <s:iterator ...> tags but could not find a way to get the contents of the Object[] to output to my JSP in a nice way. In the end the solution is:
<@s.iterator value="blogPosts" id="blogPosts" status="count">
<@s.property value="blogPosts[#count.index][0]"/>
<span class="publishedInfo">by <@s.property value="blogPosts[#count.index][2]"/> on <@s.property value="blogPosts[#count.index][1]"/></span>
</@s.iterator>
I haven't found anything else about this so hopefully this may be of use to someone. Let me know if so.
09.03.2009 09:13 - Posted by doahh - Comments: 0 - Java

Comments: