I think this solution would work, but I don't like the idea of storing the bean in the session. This significantly limits the things that user can do: 1) It is not possible to edit 2 beans in 2 windows at the same time. 2) It breaks back button - if user edits a bean, then opens other bean for editing and presses Back, he does not get the previous bean editor. And if the page was cached then even worse things happen when the form is submitted, since session already contains different bean.
Imants Quoting Ned Jackson Lovely <[EMAIL PROTECTED]>: > On Fri, Aug 31, 2007 at 06:24:58PM +0300, Imants Firsts wrote: > > How do I correctly set up a BeanEditForm for editing a > > hibernate entity? > > I don't think I'm even close to writing idiomatic Tapestry 5 (if such a > thing even exists), but here is the pattern I've been using: > > EditMyBean.java > ------- > public class EditMyBean { > > @ApplicationState > private MyDBClass _theBean; > > public MyDBClass getTheBean(){return _theBean;} > > public void onActivate(long id){ > _theBean = getDAO().getById(id); > } > public long onPassivate(){ > return _theBean.getId(); > } > > @Component(id = "beanEditForm") > private BeanEditForm _beanEditForm; > > > public void onValidate(){ > //Validate the changes. Add errors to the form using > //_beanEditForm.recordError(String). This will automagically > //cause the page to redisplay. > } > > public void onSuccess(){ > getDAO().saveOrUpdate(_theBean); > } > } > ------- > > EditMyBean.html > ------- > <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> > <head><title>EditMyBean</title></head> > <body> > > <t:beaneditform object="theBean"> > > <t:parameter name="id"> > <!-- Marking the getter or setter with @Nonvisual is far > - preferable, but this will do in a pinch. > --> > </t:parameter> > > </t:beaneditform> > > </body> > </html> > ------- > > > -- > njl --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]