You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jason lea <ja...@kumachan.net.nz> on 2007/05/22 06:38:06 UTC

T5 5.0.4 loop and checkbox

Hi,

I am new to Tapestry and have started a project where we want to use
Tapestry 5.

My question is about how I can use the  loop and checkbox with my code.

I will have a few objects to play with like User and Category.  User has a
Set of Category objects.  Category just holds an id and string that is
really a message key (for localization).

So on say the Category.html page we want to show a list of categories with a
checkbox next to each one that the user can check.
When the user submits the form we want to stuff the checked Category objects
into the User's Set.

So my Category.html might have something like
<t:form>
<tr t:type="loop" source="myList" value="rowitem">
    <td><input t:type="checkbox" t:id="myCategory" t:value="rowitem.checked"
/>${rowitem.label}</td>
</tr>
<input type="submit" />
</t:form>

Are those attributes right?
Can anyone point me in the right direction for what the Category.java should
have in it?

I think I have managed to get the rowitem.label appearing with a simple list
eg

@persist
private List myList = new ArrayList();
public List getMyList();
public void setMyList(List _myList);

(I have it populated in the constructor as an example)

What where do the values of checkbox go?  Is it some sort of indexed
property?

getMyCategory()
setMyCategory(what type goes here?)

any hints (or complete examples ;) ) would be welcome

-- 
Jason Lea

Re: T5 5.0.4 loop and checkbox

Posted by 蝈蝈龙 <el...@gmail.com>.
Category.java should look like
// Category.java
class Category{
  ...
  @persist
private List _myList = new ArrayList();
public List getMyList(){return this._myList;}
public void setMyList(List _myList){ this_myList = _myList};

// RowItem my be a DTO, just keep the checked status(from page) and label(my
from Category list)
// And the propertry name must be the same with the value of the t:value
property on Category.html   !!!
private RowItem rowitem;
public RowItem getRowitem(){ return rowitem;}
public void setRowitem(RowItem item){ this.rowitem = item; }

 // maybe you need  initialization method to initialize the RowItem then add
to _myList
 @SetupRender
  void initilaizeValue() {
    // fill RowItem
   //  add to _myList
  }

}

2007/5/22, jason lea <ja...@kumachan.net.nz>:
>
> Hi,
>
> I am new to Tapestry and have started a project where we want to use
> Tapestry 5.
>
> My question is about how I can use the  loop and checkbox with my code.
>
> I will have a few objects to play with like User and Category.  User has a
> Set of Category objects.  Category just holds an id and string that is
> really a message key (for localization).
>
> So on say the Category.html page we want to show a list of categories with
> a
> checkbox next to each one that the user can check.
> When the user submits the form we want to stuff the checked Category
> objects
> into the User's Set.
>
> So my Category.html might have something like
> <t:form>
> <tr t:type="loop" source="myList" value="rowitem">
>     <td><input t:type="checkbox" t:id="myCategory" t:value="
> rowitem.checked"
> />${rowitem.label}</td>
> </tr>
> <input type="submit" />
> </t:form>
>
> Are those attributes right?
> Can anyone point me in the right direction for what the Category.javashould
> have in it?
>
> I think I have managed to get the rowitem.label appearing with a simple
> list
> eg
>
> @persist
> private List myList = new ArrayList();
> public List getMyList();
> public void setMyList(List _myList);
>
> (I have it populated in the constructor as an example)
>
> What where do the values of checkbox go?  Is it some sort of indexed
> property?
>
> getMyCategory()
> setMyCategory(what type goes here?)
>
> any hints (or complete examples ;) ) would be welcome
>
> --
> Jason Lea
>