You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Samuel Cheung <sy...@gmail.com> on 2005/03/09 16:50:29 UTC

Create a list of Checkbox and record their values

Hi,

I want to create a form with a list of Checkbox and the names/labels of the Checkboxes are
from a list (which I create from Database). 

This is what I would like to create:
<form>
<input type="checkbox" name="bike">bike
<br>
<input type="checkbox" name="car">car
</form>


So I tapestry, in my html page, I did this:

<tr jwcid="@Foreach" element="tr" source="ognl:checkboxList" value="ognl:item">
  <td><!-- How can I add my check box here??? --> </td>
  <td><span jwcid="@Insert" value="ognl:item.name"/> <!-- this works for me, I get the right values I want from the list --> </td> 
</tr>	

note: the object Item only contains the attribute "name". It does not has an attribute of "checked" (different from the ToDo list
 example in Tapestry In Action.  
My setting the "checkboxList" is in 1 table (all choices) but the user selections is in other table.

Can someone please help me?
Thank you.

Sam



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Create a list of Checkbox and record their values

Posted by Damian Krzeminski <da...@pingtel.com>.
Samuel Cheung wrote:

>
> So I tapestry, in my html page, I did this:
>
> <tr jwcid="@Foreach" element="tr" source="ognl:checkboxList" 
> value="ognl:item">
>  <td><!-- How can I add my check box here??? --> </td>
>  <td><span jwcid="@Insert" value="ognl:item.name"/> <!-- this works 
> for me, I get the right values I want from the list --> </td> </tr>   
>
> note: the object Item only contains the attribute "name". It does not 
> has an attribute of "checked" (different from the ToDo list
> example in Tapestry In Action.  My setting the "checkboxList" is in 1 
> table (all choices) but the user selections is in other table.
>
> [..]
>
You could either use ListEdit and its "deleted" property to keep track 
of which checkbox is selected by user.
See: 
http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/form/ListEditMap.html

Or you can use a separate Map-like object to store checkboxes value.
The key is to bind "selected" property of your checkboxes to something 
that can represent you row.

If you use a separate property to track your checboxes state do this.

In your HTML:

<tr jwcid="@Foreach" element="tr" source="ognl:checkboxList" 
value="ognl:item">
 <td><span jwcid="selectedRow"/> </td>
 <td><span jwcid="@Insert" value="ognl:item.name"/> <!-- this works for 
me, I get the right values I want from the list --> </td> </tr>   

in your .page/.jwc
    <component id="selectedRow" type="Checkbox">
        <binding name="selected" 
expression="selections.selected[item.name]"/>  
    </component>

You also need to declare your selections property. And in your submit 
listener you can check which rows are selected.

There is a full example on how to do it in the project I am working on:

Map to track your checkboxes:
- 
http://scm.sipfoundry.org/rep/sipXconfig/main/web/src/org/sipfoundry/sipxconfig/components/SelectMap.java

Usage example

- 
http://scm.sipfoundry.org/rep/sipXconfig/main/web/src/org/sipfoundry/sipxconfig/components/GatewayTable.java
- 
http://scm.sipfoundry.org/rep/sipXconfig/main/web/context/WEB-INF/dialplan/GatewayTable.jwc

Damian

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org