?
Solved

Adding a multibox to nested logic\:iterate block

Posted on 2006-03-27
5
Medium Priority
?
1,009 Views
Last Modified: 2010-05-18
This is regarding a code block that I asked about in an ealier posting titled "muliple level nested logic:iterate in struts".  I have multiple levels of logic:iterate blocks and now I need to add a checkbox that will contain a value that can be saved to a list when the form is posted.

actonwang had the answer before.  Hopefully he or someone will be able to figure this out.

Here is what I have:

<logic:iterate property="subGroupList" name="GroupPurchaseForm" id="SubGroupItem" indexId="index1">

<logic:iterate name="SubGroupItem" property="travelerList" id="traveler" indexId="index2">
     <tr>
     <td style="border:0;">
          <input type="text" name='<%="SubGroupItem["+index1+"].traveler["+index2+"].tfirstname"%>' size="25" value='<bean:write name="traveler" property="tfirstname"/>' />

     </td>
       ....

I need to add a checkbox.  I tried this:

<logic:iterate property="subGroupList" name="GroupPurchaseForm" id="SubGroupItem" indexId="index1">

<logic:iterate name="SubGroupItem" property="travelerList" id="traveler" indexId="index2">
     <tr>
     <td>
          <html:multibox property="selectedtravs">
              <bean:write name='<%="SubGroupItem["+ ctr +"].traveler["+ j +"].egrseqno"%>' />
          </html:multibox>
      </td>
     <td style="border:0;">
          <input type="text" name='<%="SubGroupItem["+index1+"].traveler["+index2+"].tfirstname"%>' size="25" value='<bean:write name="traveler" property="tfirstname"/>' />
     </td>
        ....

I also tried:

<logic:iterate name="SubGroupItem" property="travelerList" id="traveler" indexId="index2">
     <tr>
     <td>
          <html:multibox property="selectedtravs">
              <bean:write name='traveler' />
          </html:multibox>
      </td>
     <td style="border:0;">
          <input type="text" name='<%="SubGroupItem["+index1+"].traveler["+index2+"].tfirstname"%>' size="25" value='<bean:write name="traveler" property="tfirstname"/>' />
     </td>
      ....

but travelerList is a list of objects so the object is copied to the value of the box.  I think it needs to be a list of values but if I change it it breaks my other code.

Do I need to use something besides a multibox for this?  If I use a regular checkbox, how are the mulitple values posted to my form?

0
Comment
Question by:csait2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16308943
Hi,

Here is the link which clearly explains the use of multibox
http://www.johntopley.com/kb/java/0027.html

You can also refer here, this also encourages to use LabelValueBean
http://husted.com/struts/tips/007.html

what is the type for selectedtravs? Is it String[] or a list of beans?

fargo
0
 

Author Comment

by:csait2
ID: 16311934
Anyone else have an answer?  I have successfully used the multibox in the first level of iteration which is based on the example you gave links to, but this solution does not work in the second level of  iteration which is what I am dealing with here.  

Here is the link to the entire code:

http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21584917.html?query=nested+logic%5C%3Aitereate+struts&clearTAFilter=true

In the code sample I gave above, selectedtravs is an ArrayList.

Thanks!
0
 

Author Comment

by:csait2
ID: 16313173
Nevermind.  I figured it out myself this time!  Here is the solution in case anyone needs to know:

<logic:iterate name="GroupPurchaseForm" property="subGroupList" id="SubGroupItem" indexId="ctr">
     ....

<logic:iterate name="SubGroupItem" property="travelerList" id="traveler" indexId="j" >
     <tr>
     <td>
          <input type="checkbox" name="selectedtravs" value='<bean:write name="traveler" property="egrseqno"/>' />
      </td>
     <td style="border:0;">
          <input type="text" name='<%="SubGroupItem["+ctr+"].traveler["+j+"].tfirstname"%>' size="25" value='<bean:write name="traveler" property="tfirstname"/>' />
     </td>

The selected values from the checkbox are loaded into String[] selectedtravs when the page is posted.   The values for the checkboxes come from the egrseqno member of the Traveler Object.  TravelerList is a list of Traveler Objects within the SubGroupItem and SubGroupList is a list of SubgroupItems.

0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16655847
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question