DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
| Code Block |
|---|
public interface IModel extends IDetachable
{
public Object getObject(final Component component);
public void setObject(final Component component, final Object object);
}
|
And the base interface IDetachable looks like this:
...
The PropertyModel class allows you to create a model that accesses a particular property of its nested model object at runtime. This property is accessed using an expression language which has a syntax similar to OGNL (see http://www.ognl.org) (until version 1.1, Wicket actually did use the OGNL library, however it has been replaced by custom implementation). The simplest PropertyModel constructor is:
...
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.
More 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 {{Wiki Markup "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 | ||
|---|---|---|
| ||
More information on the allowed property expressions can be found either in the |
...
will convert the contents of the text field to and from an Integer value.
| Warning | ||
|---|---|---|
| ||
In the event that you need more flexibility or property expressions power in your compound models, you can use the
|
...
To |
...
see |
...
how |
...
this |
...
might |
...
be |
...
used, |
...
suppose |
...
that |
...
the |
...
|
...
value |
...
needed |
...
to |
...
be |
...
bound |
...
to |
...
the |
...
property |
...
expression |
...
|
...
|
...
|
...
. |
...
In |
...
the |
...
|
...
constructor, |
...
we'd |
...
say |
...
something |
...
like |
...
this:
The |
String Resource Models
Localization of resources in Wicket is supported by the Localizer class. This provides a very convenient way to retrieve and format application and component specific resources according to the Locale that the user's Session is running under. In many cases, it will be sufficient to simply retrieve a localized String in this way, but if a formatted, localized string is desired as a model, a StringResourceModel may be used.
...
where User has a getName() method exposing its "name" property.
The Component class has convenience method which you may find useful:
| Code Block |
|---|
add(new Label("greetings", getString("label.greetings", new Model(user)))); |
Custom models
If we do not want to use the property expressions/introspection, but instead want to to pull a fresh value from the model on each request in a more strongly typed manner, we could provide our own implementation of IModel:
...