This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check for a change in value when iterating

 
Rob Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've searched trying to answer this one so would really appreciate some help to what is probably very simple!
I'm iterating through an array of objects. One of the fields in these objects is the 'group' to which the object belongs (the objects are ordered by this value).
I want to format my HTML according to when the 'group' value changes.
Here's the basics:

<logic:iterate id="feature" name="adSearchFeatures" indexId="count">
<logic:notEqual name="feature" property="group" value="<%=lastGroup%>">
<b><bean:write name="feature" property="group"/></b>
</logic:notEqual>
<html:checkbox property="name" name="feature"><bean:write name="feature" property="name"/></html:checkbox>
<!--NEED TO SET THE lastGroup HERE IN ORDER TO COMPARE ABOVE???-->
</logic:iterate>

If I can access the current 'feature' in the iteration by breaking into java that will do it as I can set a variable there, but I haven't been able to figure out how to access 'getGroup()' or 'group'.

Hope someone can help.

Thanks,

Rob
[ September 03, 2008: Message edited by: Rob CB ]
 
Rob Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Managed to solve this this morning.

Declared a variable before the iteration:

<%String lastGroup="";%>

Then set the value within the iteration:

<%lastGroup=feature.getGroup();%>

which I had already tried and failed. However, realised that you need to set the Type in the iterate tag to the type of object that is being iterated over. This makes the 'getGroup()' method available.

Would still be interesting to know of a cleaner way to do this, perhaps without breaking into code.
[ September 03, 2008: Message edited by: Rob CB ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic