Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Looking at our example POJO, the property expression "name" can be used to access the "name" property of any Person object via the getName() getter method. Also, when updating a model, using property expression "name" has the effect of calling setName(String). Hence construct a property model to use our POJO, give it a property expression "name" and set it on a TextField, not only will that TextField display the current value of the "name" property, it will also update the "name" property with any user input provided.

Wiki MarkupMore complex property expressions are possible as well. For example, you can access sub-properties via reflection using a dotted path notation, which means the property expression {{"person.name"}} is equivalent to calling {{getPerson().getName()}} on the given model object. Arrays can be accessed as in "{{persons\[4\].name}}". As you can see, PropertyModels are quite a powerful way to give Wicket components access to model objects.

Info
titleMore information on the syntax

More information on the allowed property expressions can be found either in the wicket.util.lang.PropertyResolver JavaDoc or on the Property Expression Language wiki page

...

To see how this might be used, suppose that the {{stringProperty}} value needed to be bound to the property expression {{"person\[0\].stringProperty"}}. In the {{FormInput}} constructor, we'd say something like this:

Warning
titleBoundCompoundPropertyModel has been removed in Wicket 6!

In the event that you need more flexibility or property expressions power in your compound models, you can use the BoundCompoundPropertyModel. This class provides three methods you can call on the container's model object to bind a given child Component to a specific property expression and/or type conversion:

Code Block
public Component bind(final Component component, final String propertyExpression)
public Component bind(final Component component, final Class type)
public Component bind(final Component component, final String propertyExpression, final Class type)

Wiki Markup
Code Block
super(name);
final BoundCompoundPropertyModel formModel = new BoundCompoundPropertyModel(new FormInputModel());
setModel(formModel);
add(formModel.bind(new RequiredTextField("stringProperty"), "person[0].stringProperty"));

The Form is constructed without a model. We then create the Form's model as a BoundCompoundPropertyModel, set it as the Form's model and finally use it to bind the RequiredTextField to the desired property expression.

...