• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check for a change in value when iterating

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic