wicket.model
Class PropertyModel
java.lang.Object
wicket.model.AbstractDetachableModel
wicket.model.AbstractPropertyModel
wicket.model.PropertyModel
- All Implemented Interfaces:
- java.io.Serializable, IDetachable, IModel
public class PropertyModel
- extends AbstractPropertyModel
A PropertyModel is used to dynamically access a model using a "property
expression". See PropertyResolver javadoc for allowed property
expressions.
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", new PopertyModel(person, "name"));
Where 'myLabel' is the name of the component, and 'name' is the property
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", new PropertyModel(person, "name"));
To force conversion of property value 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
PropertyResolver. This can be especially useful for when you have a
generic property (like Serializable myProp) that you want to be converted to
a narrower type (e.g. an Integer). PropertyResolver 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 an 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 a wrapped (IModel) or unwrapped (non-IModel) object and a
property expression that works on the given model. |
PropertyModel(java.lang.Object modelObject,
java.lang.String expression,
java.lang.Class propertyType)
Construct with a wrapped (IModel) or unwrapped (non-IModel) object and a
property 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 a wrapped (IModel) or unwrapped (non-IModel) object and a
property 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 - Property expression for property access
PropertyModel
public PropertyModel(java.lang.Object modelObject,
java.lang.String expression,
java.lang.Class propertyType)
- Construct with a wrapped (IModel) or unwrapped (non-IModel) object and a
property 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 - Property expression for property accesspropertyType - The type to be used for conversion instead of the type that is
figured out by the property expression code. This can be
especially useful for when you have a generic property (like
Serializable myProp) that you want to be converted to a
narrower type (e.g. an Integer). The property expression code
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 an integer, propertyType
should be set to Integer.
toString
public java.lang.String toString()
- Overrides:
toString in class AbstractPropertyModel
- See Also:
Object.toString()
propertyExpression
protected java.lang.String propertyExpression(Component component)
- Specified by:
propertyExpression in class AbstractPropertyModel
- Parameters:
component - The component to get a property expression for
- Returns:
- The property expression for the component
- See Also:
AbstractPropertyModel.propertyExpression(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-2007 Wicket developers. All Rights Reserved.