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]