aspose file tools*
The moose likes Struts and the fly likes Check for a change in value when iterating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Check for a change in value when iterating" Watch "Check for a change in value when iterating" New topic
Author

Check for a change in value when iterating

Rob Brown
Greenhorn

Joined: Sep 02, 2008
Posts: 5
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

Joined: Sep 02, 2008
Posts: 5
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check for a change in value when iterating