Reusable form fields ... the proper way disucssion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reusable form fields ... the proper way disucssion

armandoxxx
This post was updated on .
Hey guys

I would like to know how to properly do this in wicket.

I have form fields that I would like to use in several forms ...

lets say I want a model object for a
SearchFields {country, language}  << properties in brackets
and then I extend it with
UserSearchFields {userTags}
and
CustomerSearchFields {customerTags}
and put it into models ...
1. Model.of()
2. new PropertyModel(new {onOfTheseExtendedObjects}(), "{propertyName}");
3. new CompoundPropertyModel(new {onOfTheseExtendedObjects}())

so I create Common component with fields for country and language, then I create separate components for UserTagsComponent (with userTags field) and CustomerTagsComponent (with customerTags field).

I create different forms:
UserForm  which adds model of new UserSearchFields object and both Common and UserTagsComponent components .
CustomerForm which adds model of new CustomerSearchFields object and both Common and CustomerTagsComponent.

my questions are:
1. what component to use to wrap fields to reuse them and add them to form?
I tried FormComponentPanel but my model (CompoundPropertyModel) object did not include the FormComponentPanel name property; for exmaple: "searchFields", so I changed my panel with fields to ordinary Panel (then using my CompoundPropertyModel worked as expected)
2. what model implementation to use so Form would understand the fields in sub components... I tried PropertyModel ... but I had a problem when I called setDefaultModelObject(new CustomerSearchFields()) on my form ... values were not set.

I read reference and wicket book .. I understand how model implementations work .. I'm just not sure how to make it work properly If I use sub components for common fields ...

regards

Armando


 












Reply | Threaded
Open this post in threaded view
|

Re: Reusable form fields ... the proper way disucssion

Martin Grigorov-4
Hi,

Using a Panel should be fine.
Using PropertyModel is also fine.
Assuming there is a CompoundPropertyModel(Person) and Person object has an
Address, and Address has a Street then you should do:

mainModel = new CompoundPropertyModel(new Person());
form = new Form(formId, mainModel);
form.add(new AddressPanel(addressPanelId, new PropertyModel(mainModel,
"address")))

AddressPanel may have a TextField<String> for the Street:
add(new TextField<String>("street"))

or use a random tree structure and use the addressPanel's model:
anIntermediateContainer.add(new TextField<String>("str", new
PropertyModel(AddressPanel.this.getModel(), "street") ))


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Dec 16, 2014 at 1:44 AM, armandoxxx <[hidden email]>
wrote:

>
> Hey guys
>
> I would like to know to properly do this in wicket.
>
> I have form fields that I would like to use in several forms ...
>
> lets say I want a model object for a
> SearchFields {country, language}  << properties in brackets
> and then I extend it with
> UserSearchFields {userTags}
> and
> CustomerSearchFields {customerTags}
> and put it into models ...
> 1. Model.of()
> 2. new PropertyModel(new {onOfTheseExtendedObjects}(), "{propertyName}");
> 3. new CompoundPropertyModel(new {onOfTheseExtendedObjects}())
>
> so I create Common component with fields for country and language, then I
> create separate components for UserTagsComponent (with userTags field) and
> CustomerTagsComponent (with customerTags field).
>
> I create different forms:
> UserForm  which adds model of new UserSearchFields object and both Common
> and UserTagsComponent components .
> CustomerForm which adds model of new CustomerSearchFields object and both
> Common and CustomerTagsComponent.
>
> my questions are:
> 1. what component to use to wrap fields to reuse them and add them to form?
> I tried FormComponentPanel but my model (CompoundPropertyModel) object did
> not include the FormComponentPanel name property; for exmaple:
> "searchFields", so I changed my panel with fields to ordinary Panel (then
> using my CompoundPropertyModel worked as expected)
> 2. what model implementation to use so Form would understand the fields in
> sub components... I tried PropertyModel ... but I had a problem when I
> called setDefaultModelObject(new CustomerSearchFields()) on my form ...
> values were not set.
>
> I read reference and wicket book .. I understand how model implementations
> work .. I'm just not sure how to make it work properly If I use sub
> components for common fields ...
>
> regards
>
> Armando
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Reusable-form-fields-the-proper-way-disucssion-tp4668783.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Reusable form fields ... the proper way disucssion

armandoxxx
thank you ...
regards

Armando