On Thu, Dec 14, 2017 at 8:47 AM, Nathan Quirynen <
nat...@pensionarchitects.be> wrote:

> Hi,
>

Hi!


> This subject has been spoken about more in the past, but I still have not
> found a good solution to this and still struggle with this.
>
> What is the best practice (Tapestry 5.4+) to add fields to a form
> "dynamically". In my use case I just want to add some fields to a form when
> a checkbox (also part of the same form) is selected, or remove/hide them
> (in a way that they will not be validated and posted) when the checkbox is
> deselected.
>

Use BeanEditForm or BeanEditor, their 'model' parameters, which is of type
BeanModel, get one instance of it using BeanModelSource and add properties
to it using one of the beanModel.add() methods which receive a
PropertyConduit. In other words, you're creating synthetic properties, in
the sense that they don't map to an existing combination of
field/getter/setter in the class on which the BeanModel was created. Your
PropertyConduit implementation (actually, you'll probably have more than
one) is how you tell Tapestry how to get and set the value for that
property.

There's one example of doing this for editing a Map in
https://stackoverflow.com/questions/21675856/how-to-create-bean-edit-model-for-map-in-tapestry
.

--
Thiago

Reply via email to