You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ryan <rn...@gmail.com> on 2014/02/06 17:55:33 UTC

Re: Tapestry 4: form with dynamic checkboxes

Hi, is there anyone on the list that could shed some light on the problem
I'm having?

Thanks,
Ryan


On Fri, Jan 31, 2014 at 10:41 AM, Ryan <rn...@gmail.com> wrote:

> Hoping I can still get some help with Tapestry 4 on this mailing list - I
> know its old but unfortunately I'm stuck with it and cannot upgrade at this
> time.
>
> I've got a form containing a table with two columns. The table is
> constructed using contrib:TableView and the source paramter is a
> Map<String,Object>. This map is dynamically created each time the page
> renders and contains three keys:
>
> - id (int)
> - name (string)
> - checked (boolean)
>
> Here is the form:
>
>         <form jwcid="addRegion@Form">
>             <span jwcid="@Hidden" value="ognl:id"/>
>             <span jwcid="@Hidden" value="ognl:name"/>
>             <table class="form">
>                 <tr>
>                     <th>Name</th>
>                     <td><input jwcid="@TextField" displayName="Name"
> value="ognl:newRegion.name" size="40"/></td>
>                 </tr>
>                 <tr>
>                     <td></td>
>                     <td align="right">
>                         <input type="submit" jwcid="add@Submit"
> label="Add Region" class="button" listener="listener:doAdd"
> parameters="ognl:{id,name }"/>
>                     </td>
>                 </tr>
>             </table>
>             <table jwcid="sitesTable@contrib:TableView" pageSize="25"
> width="100%" class="header" source="ognl:availableSites" columns="Site
> Name:description">
>                 <tr>
>                     <td jwcid="@contrib:TableColumns" class="header"/>
>                 </tr>
>                 <tr jwcid="@contrib:TableRows" row="ognl:site"
> class="ognl:beans.evenOdd.next">
>                     <td jwcid="@contrib:TableValues" align="left"
> class="cute"/>
>                     <td align="left">
>                         <input type="checkbox" jwcid="@Checkbox"
> id="ognl:'checked_' + site.id" value="ognl:site.checked"/>
>                     </td>
>                 </tr>
>             </table>
>         </form>
>
> This form and enclosed table render properly, however the part I'm stuck
> on is how to determine that 'checked_<id>' is true. I have never been clear
> on exactly how the TableRow object needs to be wired, but I have included
> this method in my backing class:
>
> public abstract Map<String,Object> getSite();
>
> but neither the Map returned by this method nor the Map in
> 'availableSites' has the 'checked' property set to True when I try to
> determine it within my doAdd() method.
>
> From what I understand of Tapestry4 and the form component, the checkbox
> 'value' is the property that is inspected on read and set on post, which
> means it must map to a concrete, defined method or property. I can't do
> that since I'm determining the items in the map dynamically.
>
> What do you suggest?
>
> Thanks,
> Ryan
>
>

Re: Tapestry 4: form with dynamic checkboxes

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 06 Feb 2014 14:55:33 -0200, Ryan <rn...@gmail.com> wrote:

> Hi, is there anyone on the list that could shed some light on the problem
> I'm having?

The only hint I can give you is this: don't use the Map directly. Create a  
class to represent the pairs you put into the Map<String, Object> and use  
a list or collection of this new class instead of a Map<String, Object>.  
In other words, write classes to represent data structures. It'll make  
your life easier, and not just with Tapestry 4, 5 or anything else.


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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