public class InstantiatingNullHandler extends Object implements NullHandler
Provided that the key ReflectionContextState.CREATE_NULL_OBJECTS
is in the action context with a value of true (this key is set
only during the execution of the ParametersInterceptor
), OGNL expressions
that have caused a NullPointerException will be temporarily stopped for evaluation while the system automatically
tries to solve the null references by automatically creating the object.
The following rules are used when handling null references:
Collection
or List
, then an ArrayList shall be
returned and assigned to the null references.Map
, then a HashMap will be returned and assigned to the null
references.ObjectFactory.buildBean(java.lang.Class, java.util.Map)
method.For example, if a form element has a text field named person.name and the expression person evaluates to null, then this class will be invoked. Because the person expression evaluates to a Person class, a new Person is created and assigned to the null reference. Finally, the name is set on that object and the overall effect is that the system automatically created a Person object for you, set it by calling setUsers() and then finally called getUsers().setName() as you would typically expect.
Constructor and Description |
---|
InstantiatingNullHandler() |
Modifier and Type | Method and Description |
---|---|
Object |
nullMethodResult(Map<String,Object> context,
Object target,
String methodName,
Object[] args)
Method called on target returned null.
|
Object |
nullPropertyValue(Map<String,Object> context,
Object target,
Object property)
Property in target evaluated to null.
|
void |
setObjectFactory(ObjectFactory fac) |
void |
setObjectTypeDeterminer(ObjectTypeDeterminer det) |
void |
setReflectionProvider(ReflectionProvider prov) |
public void setObjectTypeDeterminer(ObjectTypeDeterminer det)
public void setReflectionProvider(ReflectionProvider prov)
public void setObjectFactory(ObjectFactory fac)
public Object nullMethodResult(Map<String,Object> context, Object target, String methodName, Object[] args)
NullHandler
nullMethodResult
in interface NullHandler
context
- contexttarget
- target objectmethodName
- method nameargs
- argumentspublic Object nullPropertyValue(Map<String,Object> context, Object target, Object property)
NullHandler
nullPropertyValue
in interface NullHandler
context
- contexttarget
- target objectproperty
- propertyCopyright © 2000–2020 Apache Software Foundation. All rights reserved.