Extending FormComponentPanel is useful if you want your panel to return some IModel<BusinessObject> that is built from the various controls on the page.

You can override convertInput and onBeforeRender to build/show the BusinessObject into the panel fields.

It can make things a lot simpler because the validation logic is lower (on the custom panels) so the form processing logic can work on just the BusinessObject's themselves.


For example:

class MyBusinessObjectPanel extends FormComponentPanel<BusinessObject> {

    private TextField nameField;

    private Calendar cal;

 ... skipping constructor, etc ...
@Override
    protected void convertInput() {

        nameField.processInput();

        cal.processInput();

        String name = nameField.getModel().getObject();

        DateTime date = cal.getModel().getObject();

        setConvertedInput (new  BusinessObject (name, date));


    }

@Override
    protected void onBeforeRender() {

        BusinessObject bo = getModelObject();

        nameField.setModelObject(bo.getName());

        cal.setModelObject(bo.getDate());

        super.onBeforeRender();

    }


Notice how the inner components of the panel don't use a property or field wise model but instead are simply a string model and a datetime model?

This allows the current value of the panel's model object to be protected. The convertedValue object is what the validation infrastructure validates (if ok then it becomes the model object).

I've found this is the best way to handle really complex forms and properly internalize their operations.

Regards,

Mike


Simply nestle sub Panel contain form components is fine if you make sure
that there are a form component higher in hierarchy. FormComponentPanel is
useful if you want the panel itself participating in form processing, I
don't think this is the case.

On Mon, Apr 11, 2011 at 10:08 AM, Chris Colman<[email protected]
wrote:
I have a complex form that I choose to break down into logical sub Panel
components and then add them as children to the Form.

The sub Panels themselves then have FormComponents like text fields and
DropDownChoice components added to them. Will the normal validate/update
mechanism simply work like that or do I need to override some methods in
my Panel classes or make the Panel classes implement certain interfaces
(eg., IFormVisitorParticipant etc.,)?

Chris Colman





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to