Link to home
Start Free TrialLog in
Avatar of csait2
csait2Flag for United States of America

asked on

Adding a multibox to nested logic\:iterate block

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?

Avatar of fargo
fargo

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
Avatar of csait2

ASKER

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:

https://www.experts-exchange.com/questions/21584917/multiple-level-nested-logic-iterate-in-struts.html?query=nested+logic\:itereate+struts&clearTAFilter=true

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

Thanks!
Avatar of csait2

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial