Package com.axelor.rpc
Class Context
- java.lang.Object
-
- javax.script.SimpleBindings
-
- com.axelor.rpc.Context
-
public class Context extends SimpleBindings
The Context class represents anActionRequestcontext.The request context is mapped to a proxy instance of the bean class on which the action is being performed. The proxy instance can be accessed via
asType(Class)method.Example (Java):
Context context = request.getContext(); SaleOrderLine soLine = context.asType(SaleOrderLine.class); SaleOrder so = context.getParentContext().asType(SaleOrder.class);
Example (Groovy):def context = request.context def soLine = context as SaleOrderLine def so = context.parentContext as SaleOrder
The instance returned from the context is a detached proxy object and should not be used with JPA/Hibernate session. It's only for convenience to get the context values using the bean methods.
-
-
Constructor Summary
Constructors Constructor Description Context(Class<?> beanClass)Create a newContextfor the given bean class.Context(Long id, Class<?> beanClass)Create a newContextfor a record by given id.Context(Map<String,Object> values, Class<?> beanClass)Create a newContextfor the given bean class using the given context values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(PropertyChangeListener listener)<T> TasType(Class<T> type)Convert the context as lazy entity of the given type.booleancontainsKey(Object key)Objectget(Object key)Class<?>getContextClass()ContextgetParent()Get parent context.protected ObjectgetTarget()Objectput(String name, Object value)protected Objectvalidate(String name, Object value)-
Methods inherited from class javax.script.SimpleBindings
clear, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
Context
public Context(Map<String,Object> values, Class<?> beanClass)
Create a newContextfor the given bean class using the given context values.- Parameters:
values- the context valuesbeanClass- the context bean class
-
Context
public Context(Class<?> beanClass)
Create a newContextfor the given bean class.- Parameters:
beanClass- the context bean class
-
-
Method Detail
-
addChangeListener
public void addChangeListener(PropertyChangeListener listener)
-
getTarget
protected Object getTarget()
-
getParent
public Context getParent()
Get parent context.- Returns:
- the parent context if exist
-
getContextClass
public Class<?> getContextClass()
-
asType
public <T> T asType(Class<T> type)
Convert the context as lazy entity of the given type.- Parameters:
type- the expected type- Returns:
- lazy initialized entity
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceBindings- Specified by:
containsKeyin interfaceMap<String,Object>- Overrides:
containsKeyin classSimpleBindings
-
-