Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using checkboxes with nested logic:iterate tags

 
Nathan England
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a difficult time with checkboxes and iterating through a few nested collections.

-My form page contains a Hashtable of OrderMaster objects.
-An OrderMaster contains an ArrayList of Order objects.
-The Order objects themselves contain an ArrayList of details.

I am displaying that structure on my JSP page as an unordered list, and I would like to have a checkbox on at least the detail level (lowest level).

My unordered list ends up looking like this:
(the [] denotes a check box)

Order (Order Master 1)
----[] Release 1(Order)
--------[] Detail 1
--------[] Detail 2
----[] Release 2 (Order)
--------[] Detail 1


I have the details of the structure displaying correctly. The data in each object is being printed to the screen. My problem is the values of the check boxes are not being submitted with the form.

Starting from the lowest level going up, here are my data objects and form.

The OrderDetail is a plain java object:


Now for my Order object, which contains a "selected" flag, and a list of OrderDetails. Another plain java object:


One more plain java object, which contains a list of Orders


Now for my ActionForm. The form object contains a table of OrderMaster objects


Here is the JSP code for my list. This seems to display the data properly for each nested iterate, however, clicking on the check box and submitting doesn't change any of the bean's "selected" value.
I can't figure out why that doesn't work:

 
Nathan England
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this have something to do with my form being in session scope?

I'm going to attempt to write some JSP that sets data in the form object when the check box is clicked, and see if that works...
 
Nathan England
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A solution!!

I finally got it to work, after much trial and error.

Multiple loops with multiple levels of check boxes work much better using Struts <nested> tags. I'm not really sure why, but using nested tags with <nested:checkbox> works like a charm. Seems really simple now.

Posting solution here. (I added an "int id;" to each of my data objects, not sure if that is relevant or not but I was simply following some examples from the web).

My ActionForm is in session scope.

(my ActionForm is parent, has list of MasterOrder objects, MasterOrder is parent of a list of Order(s) and Order is parent of a list of OrderDetail.)

The OrderDetail is a plain java object:


Now for my Order object, which contains a "selected" flag, and a list of OrderDetails. Another plain java object:


One more plain java object, which contains a list of Orders


Now for my ActionForm. The form object contains a table of OrderMaster objects

(*Side note, while doing research I may need to put code in the reset() method to handle unchecked values..if that is the case I'll post that fix below. Right now it's not really doing anything.)

Now for the JSP code. Which seems ridiculously simple now:

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic