org.apache.wicket.model
Class PropertyModel

java.lang.Object
  extended by org.apache.wicket.model.AbstractPropertyModel
      extended by org.apache.wicket.model.PropertyModel
All Implemented Interfaces:
java.io.Serializable, IClusterable, IChainingModel, IDetachable, IModel, IObjectClassAwareModel, IPropertyReflectionAwareModel

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"));
 

Note that the property resolver by default provides access to private members and methods. If guaranteeing encapsulation of the target objects is a big concern, you should consider using an alternative implementation.

Author:
Chris Turner, Eelco Hillenius, Jonathan Locke
See Also:
PropertyResolver, IModel, Model, LoadableDetachableModel, 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.
 
Method Summary
protected  java.lang.String propertyExpression()
           
 java.lang.String toString()
           
 
Methods inherited from class org.apache.wicket.model.AbstractPropertyModel
detach, getChainedModel, getObject, getObjectClass, getPropertyExpression, getPropertyField, getPropertyGetter, getPropertySetter, getTarget, onGetObject, onSetObject, setChainedModel, setObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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.

Parameters:
modelObject - The model object, which may or may not implement IModel
expression - Property expression for property access
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class AbstractPropertyModel
See Also:
Object.toString()

propertyExpression

protected java.lang.String propertyExpression()
Specified by:
propertyExpression in class AbstractPropertyModel
Returns:
The property expression for the component
See Also:
AbstractPropertyModel.propertyExpression()


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.