Well, perhaps I didn't provide enough information ... Is there someone using a custom SqueezeAdaptor, and using the beans directly in the view to edit? The examples and applications I have found use different approaches: Either by using simple Page properties (in my example, instead of product.title a String property title is used, and set before saving), or by using the bean's primary key to store and load.
My SqueezeAdaptor is similar to the HibernateTapestrySqueezer from the Wiki. I guess I stick with this, but it seems somehow dirty to use that hidden field listener. Regards, Till > -----Original Message----- > From: Till Nagel [mailto:[EMAIL PROTECTED] > Sent: Monday, February 06, 2006 5:17 PM > To: [email protected] > Subject: SqueezeAdaptor and pageBeginRender() > > Hi there, > > I am using a SqueezeAdaptor to add and edit beans - but wanted to know > if there are some better practices, than the ones I use. > > > The listener of the Page which calls the EditProduct page: > > public IPage onEdit(Product product) { > EditProduct ep = (EditProduct) getEditPage(); > ep.setProduct(product); > return ep; > } > > public IPage onAddNew() { > EditProduct ep = (EditProduct) getEditPage(); > ep.setCategory(getCategory()); > return ep; > } > > > EditProduct.java: > > public abstract class EditProduct extends BasePage implements > PageBeginRenderListener { > > @InjectObject("service:ProductService") > public abstract ProductService getProductService(); > > public abstract Product getProduct(); > public abstract void setProduct(Product product); > public abstract ProductCategory getCategory(); > > public void pageBeginRender(PageEvent event) { > if (getProduct() == null && !event.getRequestCycle().isRewinding()) > { > setProduct(new Product(getCategory())); > } > } > > public void onHiddenProduct() { > if (getProduct() == null) { > setProduct(new Product(getCategory())); > } > } > > public void onSubmit(IRequestCycle cycle) { > getProductService().save(getProduct()); > } > } > > > EditProduct.html > > <form jwcid="[EMAIL PROTECTED]" success="listener:onSubmit" > <input jwcid="@Hidden" value="ognl:product" > listener="listener:onHiddenProduct" /> > <input jwcid="[EMAIL PROTECTED]" value="ognl:product.title" /> > <!-- ... --> > </form> > > > The way Tapestry processes the form submission seems to be: > 1. pageBeginRender (rewind=true) > 2. hidden field value is unsqueezed to my bean > 3. hidden field listener > 4. Bean is getting filled, i.e. properties are set > 5. Form submit listener > 6. pageBeginRender (rewind=false) > > In 3. I (re-)create the bean the user wants to add. Without the hidden > field listener the unsqueezed bean is obviously null on adding new ones, > thus resulting in a NPE on 4. > > Is there some other approach to do this? > > Thanks, > Till > > > --------------------------------------------------------------------- > 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]
