BeanEditForm
Main Article: BeanEditForm Guide
Contents
Why do I get exceptions about instantiating a bean when using BeanEditForm?
When you render a BeanEditForm, or when the rendered form is submitted, Tapestry must instantiate an instance of the object to be edited. This occurs when the BeanEditForm's object
parameter is bound to null: Tapestry instantiates an instance of the property type so that the BeanEditForm has an object to read default values from, or to push submitted values into.
By default, this uses the standard injection mechanism, which means that Tapestry will identify the public constructor with the most parameters, and attempt to find objects and other objects for each constructor parameter.
There's two ways to fine tune this so you don't get errors:
- Place an @Inject annotation on the correct constructor to use (often, the constructor with no parameters).
public class MyBean {
@Inject
public MyBean() { ... }
// For testing
public MyBean(String value, boolean flag, int index) { ... }
...
}
- Provide an event handler method for the "prepare" event, and put an instantiated instance into the property.
public class MyPage {
@Property
public MyBean myBean;
// The template contains <t:beaneditform t:id="mybeaneditor"/> ...
void onPrepareFromMyBeanEditor() {
myBean = new MyBean();
}
}
What's the difference between BeanEditor and BeanEditForm?
BeanEditor is a component used within a BeanEditForm. A BeanEditForm simply combines a BeanEditor, a Form, and a Submit component together. Most of the capabilities of BeanEditForm are derived from the BeanEditor.
How do I customize the layout of the BeanEditForm?
The BeanEditForm is a scaffolding component; it exists to get things up and running quickly. It can be customized visually using CSS, and can be configured and extended in a number of ways ... but ultimately, if you want fine control, you should use the underlying Form, TextField and other components directly.