Package org.apache.wicket.core.util.lang
Class PropertyResolver
java.lang.Object
org.apache.wicket.core.util.lang.PropertyResolver
This class parses expressions to lookup or set a value on the object that is given.
The supported expressions are:
The supported expressions are:
- "property"
- This could be a bean property with getter and setter. Or if a map is given as an object it will be lookup with the expression as a key when there is not getter for that property.
- "property1.property2"
- Both properties are looked up as described above. If property1 evaluates to null then if there is a setter (or if it is a map) and the Class of the property has a default constructor then the object will be constructed and set on the object.
- "method()"
- The corresponding method is invoked.
- "property.index" or "property[index]"
-
If the property is a List or Array then the following expression can be a index on
that list like: 'mylist.0'. The list will grow automatically if the index is greater than the size.
This expression will also map on indexed properties, i.e.
getProperty(index)
andsetProperty(index,value)
methods. - "property.key" or "property[key]"
- If the property is a Map then the following expression can be a key in that map like: 'myMap.key'.
PropertyResolver.DefaultPropertyLocator
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.
Note: If a property evaluates to an instance of IModel
then
the expression should use '.object' to work with its value.
- Author:
- jcompagner, svenmeier
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
A wrapper for anotherPropertyResolver.IPropertyLocator
that caches results ofPropertyResolver.CachingPropertyLocator.get(Class, String)
.static class
Default locator supporting Java Beans properties, maps, lists and method invocations.static interface
A property to get and set.static interface
A locator of properties. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
destroy
(Application application) Clean up cache for this app.Get the currentPropertyResolver.IPropertyLocator
.static <T> Class<T>
getPropertyClass
(String expression, Class<?> clz) static Class<?>
getPropertyClass
(String expression, Object object) static Field
getPropertyField
(String expression, Object object) static Method
getPropertyGetter
(String expression, Object object) static Method
getPropertySetter
(String expression, Object object) static Object
Looks up the value from the object with the given expression.static void
setLocator
(Application application, PropertyResolver.IPropertyLocator locator) Set a locator for the given application.static void
setValue
(String expression, Object object, Object value, PropertyResolverConverter converter) Set the value on the object with the given expression.
-
Method Details
-
getValue
Looks up the value from the object with the given expression. If the expression, the object itself or one property evaluates to null then a null will be returned.- Parameters:
expression
- The expression string with the property to be lookup.object
- The object which is evaluated.- Returns:
- The value that is evaluated. Null something in the expression evaluated to null.
-
setValue
public static void setValue(String expression, Object object, Object value, PropertyResolverConverter converter) Set the value on the object with the given expression. If the expression can't be evaluated then a WicketRuntimeException will be thrown. If a null object is encountered then it will try to generate it by calling the default constructor and set it on the object. The value will be tried to convert to the right type with the given converter.- Parameters:
expression
- The expression string with the property to be set.object
- The object which is evaluated to set the value on.value
- The value to set.converter
- The converter to convert the value if needed to the right type.- Throws:
WicketRuntimeException
-
getPropertyClass
- Parameters:
expression
-object
-- Returns:
- class of the target property object
- Throws:
WicketRuntimeException
- if the cannot be resolved
-
getPropertyClass
- Type Parameters:
T
-- Parameters:
expression
-clz
-- Returns:
- class of the target Class property expression
- Throws:
WicketRuntimeException
- if class cannot be resolved
-
getPropertyField
- Parameters:
expression
-object
-- Returns:
- Field for the property expression
- Throws:
WicketRuntimeException
- if there is no such field
-
getPropertyGetter
- Parameters:
expression
-object
-- Returns:
- Getter method for the property expression
- Throws:
WicketRuntimeException
- if there is no getter method
-
getPropertySetter
- Parameters:
expression
-object
-- Returns:
- Setter method for the property expression
- Throws:
WicketRuntimeException
- if there is no setter method
-
destroy
Clean up cache for this app.- Parameters:
application
-
-
getLocator
Get the currentPropertyResolver.IPropertyLocator
.- Returns:
- locator for the current
Application
or a general one if no current application is present - See Also:
-
setLocator
Set a locator for the given application.- Parameters:
application
- application, may benull
locator
- locator
-