Hi onActivate() is called each time a page is loaded. So if you have a form on a page, onActivate() will be called on both at the time of rendering and submit/action phase
So if you have to initialize any variables before showing them in a form do it in prepareForRender event of the form and if you want to do some thing after submiting the form do it in prepareForSubmit event of the form. If you want to do something common in both phases do it in prepare event of the form. Please refer to http://tapestry.apache.org/tapestry5.2-dev/tapestry-core/ref/org/apache/tapestry5/corelib/components/Form.html regards taha On Sat, Apr 16, 2011 at 1:24 PM, Angelo C. <angelochen...@gmail.com> wrote: > Hi, > I have a form with email and name fields, and when the page is activated, > it will retrieve an existing application, then initialize email and name, > when submit is clicked, > a Profile record is created in onSuccess and persisted, the following > code seems not working, what is a right practice in this use case? > Thanks, > > > public class MakeProfile { > > @Inject > private Session session; > > @Property > private String email; > @Property > private String name; > > private Application app; > > void onActivate(String code_ref) { > app = (Applicantion) session().createQuery("from Applicantion where > code = ?").setString(0, code_ref).uniqueResult(); > if (app != null) { > email = app.getEmail(); > name = app.getName(); > } > } > > @CommitAfter > Object onSuccess() { > Profile p = new Profile(); > p.setEmail(email); > p.setName(name); > session.save(p); > } > > } > > > -- > View this message in context: > http://tapestry.1045711.n5.nabble.com/t5-create-a-record-from-another-table-what-is-best-practice-tp4307107p4307107.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >