You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by tomasz bandura <to...@gmail.com> on 2011/11/15 14:06:09 UTC

Dynamic form component

Hello,

I create a new topic about my idea of DynamicForm component.
Very often I use the basic version of the form that maps all the fields from
the model ( to direct manipulation of data from database )
It means simply adding all model parameters to the Form control, e.g.:
...
*form.add(textField1);
**form.add(textField2);
*...


My idea is creating a form directly from model definition:

*private DynamicsForm form = new DynamicsForm("form", CarOption.class);*//
"form" <- name, CarOption.class <- model

So the page constructor looks like ( regardless of the fields number);

*    public CarOptionEditPage() {
        addControl(form);
        form.add(new Submit("ok", " OK ", this, "onOkClicked"));
        form.add(new Submit("cancel", this, "onCancelClicked"));
    }
*


What i did till now:

*1st iteration:
*
I made several assumptions:
- field is added to the form if it has at least 'getter'
- default control type: TextField
- if field has only getter - setReadOnly(true)

*2nd iteration (annotations)*
I created prototype of annotation '@Clickable' that at this moment has just
2 options:
- type (eg. *TextField*, TextArea, HiddenField, PasswordField, Checkbox)
- required (default: false ),
for example:

@Id
    @Clickable(type = Clickable.HiddenField)
   * private Long id;*
    @Clickable(required=true)
  *  private String name;*
    @Clickable(type = Clickable.TextArea)
    *private String description;*

Of course I don't want to move code from Page to the model, but In many
cases this approach can simplify writing of code.

What is your opinion about creating DynamicForm component?

Best regards,
Tomasz