• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

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?

0
csait2
Asked:
csait2
  • 2
1 Solution
 
fargoCommented:
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
 
csait2Author Commented:
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
 
csait2Author Commented:
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
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now