T
- type of data to storeprotected static class ERXDynamicElement.ContextData<T> extends Object
You have to use begin
before first usage of the field and end
at
the end of the cycle to clean up the corresponding stack. Without balanced calls of
begin
and end
very bad things will happen. Thus it is advisable
to use a try-finally (see example below). As you have to make these calls during appendToResponse
,
taleValuesFromRequest
and invokeAction
you should put those calls into
overridden methods of beforeProcessing
and afterProcessing
respectively
to avoid code duplication.
It is advisable too to choose a unique key
, as different component types
will use the same userInfo. It is suggested to use a key composed by the component
and field name (e.g. MyDynamicElement.myField).
The ContextData field itself can and should be declared static as it doesn't store the
value itself, it is only used as an accessor to the value stored within the context.
public static final ContextData<String> myField = new ContextData<>("MyClass.myField");
public void appendToResponse(WOResponse response, WOContext context) {
beforeProcessing(context);
try {
response.appendContentString("Current value: " + myField.value(context));
} finally {
afterProcessing(context);
}
}
public void takeValuesFromRequest(WORequest request, WOContext context) {
beforeProcessing(context);
try {
…
} finally {
afterProcessing(context);
}
}
public WOActionResults invokeAction(WORequest request, WOContext context) {
beforeProcessing(context);
try {
…
} finally {
afterProcessing(context);
}
}
protected void beforeProcessing(WOContext context) {
myField.begin(context, "myValue");
}
protected void afterProcessing(WOContext context) {
myField.end(context);
}
Constructor and Description |
---|
ContextData(String key) |
Modifier and Type | Method and Description |
---|---|
void |
begin(WOContext context,
ERXDynamicElement component,
String name)
Push a value from a specific binding onto the stack.
|
void |
begin(WOContext context,
T value)
Push a constant value onto the stack.
|
void |
end(WOContext context)
Removes the current value from the stack.
|
String |
key()
The key this object uses to store values in the context's
userInfo.
|
void |
setValue(WOContext context,
T value)
Replace the current value on the stack with a new value.
|
protected Stack<T> |
stack(WOContext context) |
String |
toString() |
T |
value(WOContext context)
Returns the current value.
|
public ContextData(String key)
public String key()
public void begin(WOContext context, T value)
context
- context of the transactionvalue
- constant valuepublic void begin(WOContext context, ERXDynamicElement component, String name)
context
- context of the transactioncomponent
- the current dynamic elementname
- binding namepublic void setValue(WOContext context, T value)
context
- context of the transactionvalue
- constant valuepublic T value(WOContext context)
context
- context of the transactionpublic void end(WOContext context)
context
- context of the transactionCopyright © 2002 – 2024 Project Wonder.