public class ERXComponentActionRedirector extends Object
public WOComponent myAction() {
WOComponent nextPage = pageWithName("Main");
nextPage.takeValueForKey(Integer.valueOf(100), "someValue");
return nextPage;
}
then Main could be implemented something like this:
public class Main extends WOComponent implements ERXComponentActionRedirector.Restorable {
static Logger log = Logger.getLogger(Main.class);
public Integer someValue = Integer.valueOf(10);
public Main(WOContext aContext) {
super(aContext);
}
// this page has a "Increment Some Value" link to itself which just doubles the current value
public WOComponent addAction() {
someValue = Integer.valueOf(someValue.intValue()*2);
log.info(someValue);
return this;
}
public String urlForCurrentState() {
return context().directActionURLForActionNamed("Main$Restore", new NSDictionary(someValue, "someValue"));
}
public static class Restore extends WODirectAction {
public Restore(WORequest aRequest) {
super(aRequest);
}
public WOActionResults defaultAction() {
WOComponent nextPage = pageWithName("Main");
Number someValue = context().request().numericFormValueForKey("someValue", new NSNumberFormatter("#"));
if(someValue != null) {
nextPage.takeValueForKey(someValue, "someValue");
}
return nextPage;
}
}
}
But this is just one possibility. It only locates all the code in one place.
The major thing about this class is that you can detach URLs from actions. For example, it is very hard to create a
direct action that creates a page that uses a Tab panel or a collapsible component because you need to store a
tremendous amount of state in the URL. With this class, you say: "OK, I won't be able to totally restore everything,
but I'll show the first page with everything collapsed."
For all of this to work, your application should override the request-response loop like:
public WOActionResults invokeAction(WORequest request, WOContext context) {
WOActionResults results = super.invokeAction(request, context);
ERXComponentActionRedirector.createRedirector(results);
return results;
}
public void appendToResponse(WOResponse response, WOContext context) {
super.appendToResponse(response, context);
ERXComponentActionRedirector redirector = ERXComponentActionRedirector.currentRedirector();
if(redirector != null) {
redirector.setOriginalResponse(response);
}
}
public WOResponse dispatchRequest(WORequest request) {
ERXComponentActionRedirector redirector = ERXComponentActionRedirector.redirectorForRequest(request);
WOResponse response = null;
if(redirector == null) {
response = super.dispatchRequest(request);
redirector = ERXComponentActionRedirector.currentRedirector();
if(redirector != null) {
response = redirector.redirectionResponse();
}
} else {
response = redirector.originalResponse();
}
return response;
}
If you are using ERXApplication, you should set the
er.extensions.ERXComponentActionRedirector.enabled=true
property instead.Modifier and Type | Class and Description |
---|---|
static class |
ERXComponentActionRedirector.Observer
Observer class manages the responses cache by watching the session.
|
static interface |
ERXComponentActionRedirector.Restorable
implemented by the pages that want to be restorable
|
Modifier and Type | Field and Description |
---|---|
protected WOResponse |
originalResponse
the original response
|
protected WOResponse |
redirectionResponse
the redirection response
|
protected static NSMutableDictionary |
responses
static cache to hold the responses.
|
protected String |
sessionID
the session id for the request
|
protected String |
url
the url for the redirected request
|
Constructor and Description |
---|
ERXComponentActionRedirector(ERXComponentActionRedirector.Restorable r)
constructs the redirector from the Restorable.
|
Modifier and Type | Method and Description |
---|---|
static void |
createRedirector(WOActionResults results)
Creates and stores a Redirector if the given results implement Restorable.
|
static ERXComponentActionRedirector |
currentRedirector()
Uses ERXThreadStorage with the key "redirector".
|
WOResponse |
originalResponse() |
WOResponse |
redirectionResponse() |
static ERXComponentActionRedirector |
redirectorForRequest(WORequest request) |
String |
sessionID() |
void |
setOriginalResponse(WOResponse value)
Sets the original response.
|
protected static void |
storeRedirector(ERXComponentActionRedirector redirector)
stores the redirector in the cache.
|
String |
url() |
protected WOResponse originalResponse
protected WOResponse redirectionResponse
protected String sessionID
protected String url
protected static final NSMutableDictionary responses
public ERXComponentActionRedirector(ERXComponentActionRedirector.Restorable r)
r
- - Restorable component used to construct a redirectorprotected static void storeRedirector(ERXComponentActionRedirector redirector)
redirector
- The redirector to store.public static ERXComponentActionRedirector redirectorForRequest(WORequest request)
request
- The requestpublic static void createRedirector(WOActionResults results)
results
- public static ERXComponentActionRedirector currentRedirector()
public WOResponse redirectionResponse()
public String url()
public String sessionID()
public WOResponse originalResponse()
public void setOriginalResponse(WOResponse value)
value
- the original response.Copyright © 2002 – 2024 Project Wonder.