You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Grigoris Ioannou <ho...@gmail.com> on 2008/09/23 10:46:54 UTC

Re: Editing a collection

Same problem here.

I have a reservation form where the number of the guests is variable. So, in
my CustomerDetails.tml I have inside a form:

                <t:loop source="guests" value="guest">
                  <tr>
                    <td>Name</td>
                    <td>
                      <t:textfield t:id="guestName" value="guest.name"
validate="required"/>
                    </td>
                  </tr>
                </t:loop>

In CustomerDetails.java the code that is executed when the form is submitted
is:

    Object onSuccess() {
        System.out.println("guests are now ");
        for (Guest g : getGuests()) {
            System.out.println(g.getName());
        }
...
   }
....
The number of the guests is known beforehand and is set at the page's
onActivate:
public Object onActivate() {
             List<Guest> guests = new ArrayList();
            for (int i = 0; i < getMaxGuests().intValue(); i++) {
                Guest guest = new Guest();
                guests.add(guest);
            }
            setGuests(guests);
}


Nevertheless, the names of the guests are always null. Perhaps this is not
the "right" way to enter multiple values? Any suggestions?

Regards,
Grigoris


On Tue, Jan 29, 2008 at 4:19 PM, Michael Courcy <mi...@gmail.com>wrote:

> Hi François
>
> Thanks a lot, but actually my goal was more on understanding the loop
> inside the form and how the model is updated in such situation.
>
> I keep your link though, I'll have a look on it.
>
>
> Michael.
>
> Francois Armand a écrit :
>
>  Michael Courcy wrote:
>>
>>> You mean that using value="user.loginUser" tapestry alway update the same
>>> thing.
>>> Thus if I change the method
>>>
>>> User {
>>> void setLoginUser(String loginUser){
>>>  this.loginUser = loginUser;
>>>  System.out.println(loginUser);
>>> }
>>>
>>> It should at least output the value I input in my textField ...
>>> And that's right, it actually what's going on the input are correctly
>>> output
>>>
>>> But When I outout the user itself in the page
>>>
>>> public void setUser(User user) {
>>>       this.user = user;
>>>       System.out.println(user);
>>>   }
>>>
>>> the old value is kept
>>>
>>> actually setUser is call before setLoginUser ...
>>>
>>> Ok thanks I've to work on that.
>>>
>>
>> If you want, I built a "ListEditor" to handle this kind of things. It's
>> part of my project, http://interldap.org
>> What you may looking for is here :
>> http://svn.forge.objectweb.org/cgi-bin/viewcvs.cgi/interldap/interldap-wui-common/trunk/src/main/java/org/interldap/wui/t5lib/components/ListEditor.java?view=markup&rev=672
>> And here there is an example of use case (it really lacks a lot of doc) :
>>
>> http://svn.forge.objectweb.org/cgi-bin/viewcvs.cgi/interldap/interldap-wui-common/trunk/src/main/resources/org/interldap/wui/t5lib/components/eschema/EditAttribute.tml?view=markup&rev=568
>>
>> That build a list of input fields, with a [delete] button next to them,
>> and [add new value] button at the end of the list.
>> Each button emits an events so that enclosing component can add or delete
>> matching value from list.
>> When you click on a button, updated values are set in the list at the
>> right place.
>>
>> It may be use to construct simpler list editor.
>>
>> Hope it may help !
>>
>>
>
> --
> Michael Courcy
> http://courcy.blogspot.com
> http://courcy-en.blogspot.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Nikolaos Konstantinou
PhD Student - Research Assistant
http://www.cn.ntua.gr/~nkons