• 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

Using checkboxes with nested logic:iterate tags

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic