Re: [T5] Problem with multiple forms in a loop
I didn't see Olof's original post, but this is what the PREPARE event is for. Use it to set up the object that is being edited using the form context. Also, note that there is a limitation with form validation. From the docs: - tracker - org.apache.tapestry.ValidationTracker - defaultTracker - prop - The object which will record user input and validation errors. The object must be persistent between requests (since the form submission and validation occurs in an component event request and the subsequent render occurs in a render request). The default is a persistent property of the Form component and this is sufficient for nearly all purposes __ (except when a Form is rendered inside a loop). __ Cheers, Nick. Angelo Chen wrote: Hi, oic, maybe an ajax will do? I am thinking of providing a hidden form, when user click a link in one record, it will insert the hidden form below the selected row for user to edit, then submit it via an ajax call and close the form, not yet tried. A.C. "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: I'm afraid not. I ended up with enclosing all users in one big form. I thought it wasn't worth solving when the one form approach worked just fine in my case. /Olof On 29/10/2007, Angelo Chen <[EMAIL PROTECTED]> wrote: Hi Olof, Did you find a solution to this? I have similar need as yours this time. A.C. "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: I have a problem with using forms in components where the data model is passed to the components via parameter inside a T5 loop component. When a form is submitted the data model seems to be lost. What I'm trying to do is to iterate through a collection of users and construct a form for each user where a user name can be edited. Each form resides in a component that handles submission. The user model data is passed to the component inside a page where a loop loops through a collection of users. The idea is to have a form for each user so when submitting a form, only the user edited will get updated. However, when a form is submitted the user data model is lost and ends up as a null pointer. I wouldn't be surprised if I've missed something obvious or if the way I try to achieve a form for each user isn't a valid usage of T5. Any thoughts or suggestions? I've attached a simple example demonstrating my approach in this email. /Olof // User.java Data Model package org.example; public class User { private String name; public User(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } //Users.java T5 Page package org.example.testapp.pages; import java.util.ArrayList; import java.util.List; import org.apache.tapestry.annotations.Persist; import org.example.User; public class Users { private User user; @Persist("flash") private List users; public void onActivate() { if (users == null) { users = new ArrayList(); users.add(new User("Ted")); users.add(new User("Olof")); } } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public List getUsers() { return users; } } // Users.html T5 Template http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> //EditUser.java T5 Component package org.example.testapp.components; import org.apache.tapestry.annotations.Parameter; import org.example.User; public class EditUser { @Parameter(required = true) private User user; public void setUser(User user) { this.user = user; } public User getUser() { return user; } public void onSuccess() { // save user } } //EditUser.html T5 Template http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/-T5--Problem-with-multiple-forms-in-a-loop-tf4533944.html#a13467431 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5] Problem with multiple forms in a loop
Hi, oic, maybe an ajax will do? I am thinking of providing a hidden form, when user click a link in one record, it will insert the hidden form below the selected row for user to edit, then submit it via an ajax call and close the form, not yet tried. A.C. "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: > > I'm afraid not. I ended up with enclosing all users in one big form. I > thought it wasn't worth solving when the one form approach worked just > fine in my case. > > /Olof > > On 29/10/2007, Angelo Chen <[EMAIL PROTECTED]> wrote: >> >> Hi Olof, >> >> Did you find a solution to this? I have similar need as yours this time. >> >> A.C. >> >> >> "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: >> > >> > I have a problem with using forms in components where the data model >> > is passed to the components via parameter inside a T5 loop component. >> > When a form is submitted the data model seems to be lost. >> > >> > What I'm trying to do is to iterate through a collection of users and >> > construct a form for each user where a user name can be edited. Each >> > form resides in a component that handles submission. The user model >> > data is passed to the component inside a page where a loop loops >> > through a collection of users. The idea is to have a form for each >> > user so when submitting a form, only the user edited will get updated. >> > However, when a form is submitted the user data model is lost and ends >> > up as a null pointer. >> > >> > I wouldn't be surprised if I've missed something obvious or if the way >> > I try to achieve a form for each user isn't a valid usage of T5. Any >> > thoughts or suggestions? I've attached a simple example demonstrating >> > my approach in this email. >> > >> > /Olof >> > >> > // User.java Data Model >> > package org.example; >> > >> > public class User >> > { >> > private String name; >> > >> > public User(String name) >> > { >> > this.name = name; >> > } >> > >> > public String getName() >> > { >> > return name; >> > } >> > >> > public void setName(String name) >> > { >> > this.name = name; >> > } >> > } >> > >> > //Users.java T5 Page >> > package org.example.testapp.pages; >> > >> > import java.util.ArrayList; >> > import java.util.List; >> > >> > import org.apache.tapestry.annotations.Persist; >> > import org.example.User; >> > >> > public class Users >> > { >> > private User user; >> > >> > @Persist("flash") >> > private List users; >> > >> > public void onActivate() >> > { >> > if (users == null) >> > { >> > users = new ArrayList(); >> > users.add(new User("Ted")); >> > users.add(new User("Olof")); >> > } >> > } >> > >> > public User getUser() >> > { >> > return user; >> > } >> > >> > public void setUser(User user) >> > { >> > this.user = user; >> > } >> > >> > public List getUsers() >> > { >> > return users; >> > } >> > } >> > >> > // Users.html T5 Template >> > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > //EditUser.java T5 Component >> > package org.example.testapp.components; >> > >> > import org.apache.tapestry.annotations.Parameter; >> > import org.example.User; >> > >> > public class EditUser >> > { >> > @Parameter(required = true) >> > private User user; >> > >> > public void setUser(User user) >> > { >> > this.user = user; >> > } >> > >> > public User getUser() >> > { >> > return user; >> > } >> > >> > public void onSuccess() >> > { >> >
Re: [T5] Problem with multiple forms in a loop
I'm afraid not. I ended up with enclosing all users in one big form. I thought it wasn't worth solving when the one form approach worked just fine in my case. /Olof On 29/10/2007, Angelo Chen <[EMAIL PROTECTED]> wrote: > > Hi Olof, > > Did you find a solution to this? I have similar need as yours this time. > > A.C. > > > "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: > > > > I have a problem with using forms in components where the data model > > is passed to the components via parameter inside a T5 loop component. > > When a form is submitted the data model seems to be lost. > > > > What I'm trying to do is to iterate through a collection of users and > > construct a form for each user where a user name can be edited. Each > > form resides in a component that handles submission. The user model > > data is passed to the component inside a page where a loop loops > > through a collection of users. The idea is to have a form for each > > user so when submitting a form, only the user edited will get updated. > > However, when a form is submitted the user data model is lost and ends > > up as a null pointer. > > > > I wouldn't be surprised if I've missed something obvious or if the way > > I try to achieve a form for each user isn't a valid usage of T5. Any > > thoughts or suggestions? I've attached a simple example demonstrating > > my approach in this email. > > > > /Olof > > > > // User.java Data Model > > package org.example; > > > > public class User > > { > > private String name; > > > > public User(String name) > > { > > this.name = name; > > } > > > > public String getName() > > { > > return name; > > } > > > > public void setName(String name) > > { > > this.name = name; > > } > > } > > > > //Users.java T5 Page > > package org.example.testapp.pages; > > > > import java.util.ArrayList; > > import java.util.List; > > > > import org.apache.tapestry.annotations.Persist; > > import org.example.User; > > > > public class Users > > { > > private User user; > > > > @Persist("flash") > > private List users; > > > > public void onActivate() > > { > > if (users == null) > > { > > users = new ArrayList(); > > users.add(new User("Ted")); > > users.add(new User("Olof")); > > } > > } > > > > public User getUser() > > { > > return user; > > } > > > > public void setUser(User user) > > { > > this.user = user; > > } > > > > public List getUsers() > > { > > return users; > > } > > } > > > > // Users.html T5 Template > > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > > > > > > > > > > > > > > > > //EditUser.java T5 Component > > package org.example.testapp.components; > > > > import org.apache.tapestry.annotations.Parameter; > > import org.example.User; > > > > public class EditUser > > { > > @Parameter(required = true) > > private User user; > > > > public void setUser(User user) > > { > > this.user = user; > > } > > > > public User getUser() > > { > > return user; > > } > > > > public void onSuccess() > > { > > // save user > > } > > } > > > > //EditUser.html T5 Template > > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > > > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > View this message in context: > http://www.nabble.com/-T5--Problem-with-multiple-forms-in-a-loop-tf4533944.html#a13467431 > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5] Problem with multiple forms in a loop
Hi Olof, Did you find a solution to this? I have similar need as yours this time. A.C. "Olof =?UTF-8?Q?N=C3=A6ss=C3=A9n" ?= wrote: > > I have a problem with using forms in components where the data model > is passed to the components via parameter inside a T5 loop component. > When a form is submitted the data model seems to be lost. > > What I'm trying to do is to iterate through a collection of users and > construct a form for each user where a user name can be edited. Each > form resides in a component that handles submission. The user model > data is passed to the component inside a page where a loop loops > through a collection of users. The idea is to have a form for each > user so when submitting a form, only the user edited will get updated. > However, when a form is submitted the user data model is lost and ends > up as a null pointer. > > I wouldn't be surprised if I've missed something obvious or if the way > I try to achieve a form for each user isn't a valid usage of T5. Any > thoughts or suggestions? I've attached a simple example demonstrating > my approach in this email. > > /Olof > > // User.java Data Model > package org.example; > > public class User > { > private String name; > > public User(String name) > { > this.name = name; > } > > public String getName() > { > return name; > } > > public void setName(String name) > { > this.name = name; > } > } > > //Users.java T5 Page > package org.example.testapp.pages; > > import java.util.ArrayList; > import java.util.List; > > import org.apache.tapestry.annotations.Persist; > import org.example.User; > > public class Users > { > private User user; > > @Persist("flash") > private List users; > > public void onActivate() > { > if (users == null) > { > users = new ArrayList(); > users.add(new User("Ted")); > users.add(new User("Olof")); > } > } > > public User getUser() > { > return user; > } > > public void setUser(User user) > { > this.user = user; > } > > public List getUsers() > { > return users; > } > } > > // Users.html T5 Template > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > > > > > > //EditUser.java T5 Component > package org.example.testapp.components; > > import org.apache.tapestry.annotations.Parameter; > import org.example.User; > > public class EditUser > { > @Parameter(required = true) > private User user; > > public void setUser(User user) > { > this.user = user; > } > > public User getUser() > { > return user; > } > > public void onSuccess() > { > // save user > } > } > > //EditUser.html T5 Template > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/-T5--Problem-with-multiple-forms-in-a-loop-tf4533944.html#a13467431 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5] Problem with multiple forms in a loop
This gets to be tricky stuff. Remember that a form submissions starts with the page instance, with its persisted fields rolled back to their latest values. Anything that isn't @Persist will be in a null or default state. What's going on here is that your form is dependent on same transitory state; that is, state that exists ephemerally during the rendering process. That isn't a problem, except that the data you need is no longer available when the form is submitted. You could try to handle this much like an ActionLink, using the context parameter of the form. That context is provided to the "prepare" event (i.e., the onPrepare() method). The prepare event is fired as part of the initial render, and at the start of the form submission. In your case, the logical context value would be the user name, or some form of user id. In this way, you take direct control of the state information encoded into your form, and provided back when the form is submitted. On 9/28/07, Olof Næssén <[EMAIL PROTECTED]> wrote: > > I have a problem with using forms in components where the data model > is passed to the components via parameter inside a T5 loop component. > When a form is submitted the data model seems to be lost. > > What I'm trying to do is to iterate through a collection of users and > construct a form for each user where a user name can be edited. Each > form resides in a component that handles submission. The user model > data is passed to the component inside a page where a loop loops > through a collection of users. The idea is to have a form for each > user so when submitting a form, only the user edited will get updated. > However, when a form is submitted the user data model is lost and ends > up as a null pointer. > > I wouldn't be surprised if I've missed something obvious or if the way > I try to achieve a form for each user isn't a valid usage of T5. Any > thoughts or suggestions? I've attached a simple example demonstrating > my approach in this email. > > /Olof > > // User.java Data Model > package org.example; > > public class User > { > private String name; > > public User(String name) > { > this.name = name; > } > > public String getName() > { > return name; > } > > public void setName(String name) > { > this.name = name; > } > } > > //Users.java T5 Page > package org.example.testapp.pages; > > import java.util.ArrayList; > import java.util.List; > > import org.apache.tapestry.annotations.Persist; > import org.example.User; > > public class Users > { > private User user; > > @Persist("flash") > private List users; > > public void onActivate() > { > if (users == null) > { > users = new ArrayList(); > users.add(new User("Ted")); > users.add(new User("Olof")); > } > } > > public User getUser() > { > return user; > } > > public void setUser(User user) > { > this.user = user; > } > > public List getUsers() > { > return users; > } > } > > // Users.html T5 Template > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > > > > > > //EditUser.java T5 Component > package org.example.testapp.components; > > import org.apache.tapestry.annotations.Parameter; > import org.example.User; > > public class EditUser > { > @Parameter(required = true) > private User user; > > public void setUser(User user) > { > this.user = user; > } > > public User getUser() > { > return user; > } > > public void onSuccess() > { > // save user > } > } > > //EditUser.html T5 Template > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Howard M. Lewis Ship Partner and Senior Architect at Feature50 Creator Apache Tapestry and Apache HiveMind
[T5] Problem with multiple forms in a loop
I have a problem with using forms in components where the data model is passed to the components via parameter inside a T5 loop component. When a form is submitted the data model seems to be lost. What I'm trying to do is to iterate through a collection of users and construct a form for each user where a user name can be edited. Each form resides in a component that handles submission. The user model data is passed to the component inside a page where a loop loops through a collection of users. The idea is to have a form for each user so when submitting a form, only the user edited will get updated. However, when a form is submitted the user data model is lost and ends up as a null pointer. I wouldn't be surprised if I've missed something obvious or if the way I try to achieve a form for each user isn't a valid usage of T5. Any thoughts or suggestions? I've attached a simple example demonstrating my approach in this email. /Olof // User.java Data Model package org.example; public class User { private String name; public User(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } //Users.java T5 Page package org.example.testapp.pages; import java.util.ArrayList; import java.util.List; import org.apache.tapestry.annotations.Persist; import org.example.User; public class Users { private User user; @Persist("flash") private List users; public void onActivate() { if (users == null) { users = new ArrayList(); users.add(new User("Ted")); users.add(new User("Olof")); } } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public List getUsers() { return users; } } // Users.html T5 Template http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> //EditUser.java T5 Component package org.example.testapp.components; import org.apache.tapestry.annotations.Parameter; import org.example.User; public class EditUser { @Parameter(required = true) private User user; public void setUser(User user) { this.user = user; } public User getUser() { return user; } public void onSuccess() { // save user } } //EditUser.html T5 Template http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]