wicket.model
Class PropertyModel
java.lang.Object
wicket.model.AbstractDetachableModel
wicket.model.AbstractPropertyModel
wicket.model.PropertyModel
- All Implemented Interfaces:
- IDetachable, IModel, java.io.Serializable
- public class PropertyModel
- extends AbstractPropertyModel
A PropertyModel is used to dynamically access a model using an Ognl expression .
For example, take the following bean:
public class Person
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
We could construct a label that dynamically fetches the name property of the
given person object like this:
Person person = getSomePerson();
...
add(new Label("myLabel", person, "name");
Where 'myLabel' is the name of the component, and 'name' is the Ognl
expression to get the name property.
In the same fashion, we can create form components that work dynamically on
the given model object. For instance, we could create a text field that
updates the name property of a person like this:
add(new TextField("myTextField", person, "name");
To force Ognl to convert to a specific type, you can provide constructor
argument 'propertyType'.if that is set, that type is used for conversion
instead of the type that is figured out by Ognl. This can be especially
usefull for when you have a generic property (like Serializable myProp) that
you want to be converted to a narrower type (e.g. an Integer). Ognl sees an
incomming string being compatible with the target property, and will then
bypass the converter. Hence, to force myProp being converted to and from and
integer, propertyType should be set to Integer.
- Author:
- Chris Turner, Eelco Hillenius, Jonathan Locke
- See Also:
IModel,
Model,
AbstractDetachableModel,
Serialized Form
|
Constructor Summary |
PropertyModel(java.lang.Object modelObject,
java.lang.String expression)
Construct with an IModel object and a Ognl expression that works on the
given model. |
PropertyModel(java.lang.Object modelObject,
java.lang.String expression,
java.lang.Class propertyType)
Construct with an IModel object and a Ognl expression that works on the
given model. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
PropertyModel
public PropertyModel(java.lang.Object modelObject,
java.lang.String expression)
- Construct with an IModel object and a Ognl expression that works on the
given model. Additional formatting will be used depending on the
configuration setting.
- Parameters:
modelObject - The model object, which may or may not implement IModelexpression - Ognl expression for property access
PropertyModel
public PropertyModel(java.lang.Object modelObject,
java.lang.String expression,
java.lang.Class propertyType)
- Construct with an IModel object and a Ognl expression that works on the
given model. Additional formatting will be used depending on the
configuration setting.
- Parameters:
modelObject - The model object, which may or may not implement IModelexpression - Ognl expression for property accesspropertyType - The type to be used for conversion instead of the type that is
figured out by Ognl. This can be especially usefull for when
you have a generic property (like Serializable myProp) that
you want to be converted to a narrower type (e.g. an Integer).
Ognl sees an incoming string being compatible with the target
property, and will then bypass the converter. Hence, to force
myProp being converted to and from and integer, propertyType
should be set to Integer.
toString
public java.lang.String toString()
- See Also:
Object.toString()
ognlExpression
protected java.lang.String ognlExpression(Component component)
- Specified by:
ognlExpression in class AbstractPropertyModel
- Parameters:
component - The component to get an OGNL expression for
- Returns:
- The OGNL expression for the component
- See Also:
AbstractPropertyModel.ognlExpression(wicket.Component)
propertyType
protected java.lang.Class propertyType(Component component)
- Specified by:
propertyType in class AbstractPropertyModel
- Parameters:
component - The component
- Returns:
- The property type
- See Also:
AbstractPropertyModel.propertyType(wicket.Component)
Copyright © 2004-2005 Wicket developers. All Rights Reserved.