We do this kind of thing a lot, and the way we've tended to do it is slightly different. I think the simplest way to do this is to give all the checkboxes the same names, but different values (pulled out of wherever you like). For example:

<display:table uid="row">
    <display:column ... >
<input type="checkbox" name="selectedIds" value="$ {row.mappingId}"/>
    </display:column>
</display:table>

That way when this posts back to the server you end up with a single form field called "selectedIds" that has multiple values. In Struts you would simply declare this probably as a String array (maybe a Long array if you are brave):
        private String[] selectedIds;

The array will contain an item for each checked checkbox in the submission. As for accessing the value the value without using a tag....in newer JSP containers (I think it's Servlet 2.2, but I can't remember for sure) you can us EL anywhere on the page and the container will evaluate it for you. The id or uid attributes on the table tag specify the name of an EL variable where each row of the table is set during iteration over the rows. Does that make sense?

Also of interest, if you have fairly large tables that you are doing this for you might like to take a look at a chunk of JavaScript that I wrote that will give you GMail style shift-click ability to select ranges of checkboxes :) http://jroller.com/page/tfenne/? anchor=checkbox_range_selection_in_javascript

-Tim Fennell
Stripes: http://stripes.mc4j.org/


On Mar 9, 2006, at 9:15 AM, Dean Pullen wrote:

Thanks for your answer.

Ok. Well I already have something working which is pretty much similar:

<display:table name="sessionScope.cdsMappingBeans" uid="bean" >
    <input type="checkbox" name="<c:out value="${bean.mappingId}" />"
                                                 value="<c:out
value="${bean.mappingId}" />">
</display:table>

I'm not sure I understand how to use the syntax you are using, i.e.
name="myList[${myItem.id}]" without some tag decleration?

Unfortunately the 'mappingId's' are refer to are not the actual index
of the list, they're independent. If I need to use some kind of map
based on a key id then I will.

Even so, I am still unsure how I would then determine which have been
selected in the resulting struts action once the submission had been
made.

Thanks for you help.

On 09/03/06, Rick Herrick <[EMAIL PROTECTED]> wrote:
Short answer: Yhere's nothing directly in displaytag for handling this.

Longer answer: You can use the implicit row object along with the BeanUtils
library to create these controls, something like:

<display:table name="myList" uid="myItem">
  <display:column title="...">
    <input type="checkbox" name="myList[${myItem.id}]"
value="${myItem.property}"/>
      ${myItem.property}
   </display:column>
</display:table>

This assumes that the id of each row is the index of the row in the list.
This also works when the id is the key in a map, although it's less
straightforward.

Most satisfying answer: I think I have a little sandbox app that illustrates this functionality. I created it when I was trying to figure out how to do this myself. If I can find it, I'll post it somewhere. In the meantime, if you try to implement this yourself, post any questions you might run into.

But the things that you want to do are entirely possible.  I use both
checkboxes and select lists with displaytag all the time.

Rick Herrick
[EMAIL PROTECTED]


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:displaytag-user-
[EMAIL PROTECTED] On Behalf Of Dean Pullen
Sent: Thursday, March 09, 2006 4:57 AM
To: displaytag-user@lists.sourceforge.net
Subject: [displaytag-user] Selection/Checkbox Tutorial

Hi. I'm very much looking forward to integrating this taglib into our
project(s).

However, I am still very unsure how to implement multiple- selection of
table rows via checkbox functionality. This is not within the
tutorials and I can find no definitive (or even rough description) of how to implement a checkbox selection methodology using the displaytab
taglib.

(Also how to incorporate this into the export funtionality would be
great).

If anyone could point me in the right direction, I'd appreciate it.

Dean.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the live
webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to