You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Apte, Dhanashree (Noblestar)" <DA...@jims.hctx.net> on 2005/06/29 21:31:06 UTC
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.
Re: Checkbox question
Posted by Laurie Harper <la...@holoweb.net>.
Apte, Dhanashree (Noblestar) wrote:
> <td width=1%><html:checkbox name="aBean" property="temporaryId"
> value="temporaryId" /></td>
...
> 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".
That's because you've explicitly set value="temporaryId". Either remove the
value attribute, or use an expression to set it to what you want instead of
a static string.
--
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/~laurie/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Checkbox question
Posted by ba...@tcs.com.
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: basudeb.acharya@tcs.com
Website: http://www.tcs.com
"Apte, Dhanashree (Noblestar)" <DA...@jims.hctx.net>
06/30/2005 01:01 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
"'Struts Users Mailing List'" <us...@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
Re: Checkbox question
Posted by Phani <ph...@yahoo.com>.
Hi Apte..
Here is another simple sol. which gives you an array
containing the row id's of all the checkBoxes which
are checked...
I am using Display Tag to display the lists:
<display:table defaultsort="3" class=""
name="partItems" id="partItem" >
<display:column titleKey="{*}">
<html:multibox name="partDetailForm"
property="intarray"><%=partItem_rowNum%></html:multibox>
</display:column>
<display:column property="sku" paramId="Sku"
title="SKU" align="right" />
<display:column property="partNo" title="Part Number"
align="right" />
</display:table>
In my ActionForm I have an
int[] intarray
which collects the values of the selected checkboxes.
See the documentation of <html:multibox> at
http://struts.apache.org/userGuide/struts-html.html#multibox.
My Action works on the intarray to do the proper thing
with the values.
Remember to set intarray to zero length in the reset
method of the ActionForm.
Phani.
--- "Apte, Dhanashree (Noblestar)"
<DA...@jims.hctx.net> wrote:
> 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.
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org