Hi Apte,

 The problem is due to the fact that when an array of checkboxes are 
submitted only the checkboxes which are checked are sent back to the 
server and that does not contain the index of the checkbox as laid out in 
the form, for example if there are 10 checkboxes (with same name) in a 
form and only checkbox number 2 and checkbox number 6 is checked, the 
server receives only an array of 2 elements and it is not possible to find 
out which checkboxes were clicked.

Solution: -
--------------

 We got around this problem by using a hidden textbox, a javascript 
function and indexId attribute of logic:iterate which is fired on clicking 
of the checkbox. So, your code can be rewritten as below: -

 <script>
function boxClicked(val)
{
    if(document.getElementsByName("myCheckBox")[val].checked)
    {
      alert(val);
      document.getElementsByName("itemChecked")[val].value = "Y";
    }
    else
    {
      document.getElementsByName("itemChecked")[val].value = "N";
    }
 
}
</script>

 Your jsp could look like this: -

<logic:iterate id="aBean" name="myForm" property="allRecords" 
indexId="idx">
<tr
class=<%RecordCounter++;
bgcolor = "alternateRow";
if (RecordCounter % 2 == 1)
bgcolor = "normalRow";
out.print(bgcolor);%>>
<td width=1%><html:checkbox name="aBean" property="myCheckBox" 
alt="<%=idx%>" />
<html:hidden property="itemChecked" name="aBean" /><html:hidden 
property="temporaryId" name="aBean" /></td> 
<td class=formDe><bean:write name="aBean" property="attr1" /></td>
<td class=formDe><bean:write name="aBean" property="attr2" /></td>
<td class=formDe><bean:write name="aBean" property="attr3" /></td>
<td class=formDe><bean:write name="aBean" property="attr4" /></td>
<td class=formDe><bean:write name="aBean" property="attr5" /></td>  
</tr>
</logic:iterate> 


You shall receive String [] itemChecked from the action and can find out 
which checkboxes are clicked, if you want to get the value of the 
temporary id  as well please use another hidden field as above.

Regards,
Basudeb Acharya
Tata Consultancy Services Limited
Mailto: [EMAIL PROTECTED]
Website: http://www.tcs.com




"Apte, Dhanashree (Noblestar)" <[EMAIL PROTECTED]> 
06/30/2005 01:01 AM
Please respond to
"Struts Users Mailing List" <user@struts.apache.org>


To
"'Struts Users Mailing List'" <user@struts.apache.org>
cc

Subject
Checkbox question






Hi all,

I have a jsp which shows rows of data. Each row is preceded by a checkbox. 
i
can check the boxes and hit a delete button and it is supposed to delete 
the
selected rows. In my page i have:

<logic:iterate id="aBean" name="myForm" property="allRecords">
<tr
class=<%RecordCounter++;
bgcolor = "alternateRow";
if (RecordCounter % 2 == 1)
bgcolor = "normalRow";
out.print(bgcolor);%>>
<td width=1%><html:checkbox name="aBean" property="temporaryId"
value="temporaryId" /></td> 
<td class=formDe><bean:write name="aBean" property="attr1" /></td>
<td class=formDe><bean:write name="aBean" property="attr2" /></td>
<td class=formDe><bean:write name="aBean" property="attr3" /></td>
<td class=formDe><bean:write name="aBean" property="attr4" /></td>
<td class=formDe><bean:write name="aBean" property="attr5" /></td>  
</tr>
</logic:iterate> 

I am unable to identify the rows uniquely by clicking on the checkboxes. 
The
syntax for one of the two would help:

I would like to use the value of the RecordCounter to get submitted as the
checkbox value. (but i dont know the syntax). OR..

I would like to have the vaue of the field temporaryId passed back. right
now, with what i have, i just get a String array called temporaryId and
temporaryId[0] = "temporaryId", temporaryID[1]="temporaryId". I want the
actual value of the temporaryId attribute back instead of just
"temporaryId".

Any help is appreciated.

Thanks!
Dhanashree.


ForwardSourceID:NT00005F42 


Notice: The information contained in this e-mail message and/or attachments to 
it may contain confidential or privileged information.   If you are not the 
intended recipient, any dissemination, use, review, distribution, printing or 
copying of the information contained in this e-mail message and/or attachments 
to it are strictly prohibited.   If you have received this communication in 
error, please notify us by reply e-mail or telephone and immediately and 
permanently delete the message and any attachments.  Thank you

Reply via email to