|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecter.extensions.appserver.ERXComponentActionRedirector
public class ERXComponentActionRedirector
Allows you to develop your app using component actions while still providing bookmarkable URLs.
It should be considered highly experimental and it uses a few very dirty shortcuts, but no private API to work it's magic.
The main problems may be garbage collection or space requirements. You might be better off to compress the responses.
The mode of operation is as follows; given a component action in a typical page:
then Main could be implemented something like this:
public WOComponent myAction() {
WOComponent nextPage = pageWithName("Main");
nextPage.takeValueForKey(new Integer(100), "someValue");
return nextPage;
}
But this is just one possibility. It only locates all the code in one place.
public class Main extends WOComponent implements ERXComponentActionRedirector.Restorable {
static Logger log = Logger.getLogger(Main.class);
public Integer someValue = new Integer(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 = new Integer(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;
}
}
}
The actual workings are:
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.
Nested Class Summary | |
---|---|
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 |
Field Summary | |
---|---|
protected static org.apache.log4j.Logger |
log
logging support |
protected com.webobjects.appserver.WOResponse |
originalResponse
the original response |
protected com.webobjects.appserver.WOResponse |
redirectionResponse
the redirection response |
protected static com.webobjects.foundation.NSMutableDictionary |
responses
static cache to hold the responses. |
protected java.lang.String |
sessionID
the session id for the request |
protected java.lang.String |
url
the url for the redirected request |
Constructor Summary | |
---|---|
ERXComponentActionRedirector(ERXComponentActionRedirector.Restorable r)
contructs the redirector from the Restorable. |
Method Summary | |
---|---|
static void |
createRedirector(com.webobjects.appserver.WOActionResults results)
Creates and stores a Redirector if the given results implement Restorable. |
static ERXComponentActionRedirector |
currentRedirector()
Uses ERXThreadStorage with the key "redirector". |
com.webobjects.appserver.WOResponse |
originalResponse()
|
com.webobjects.appserver.WOResponse |
redirectionResponse()
|
static ERXComponentActionRedirector |
redirectorForRequest(com.webobjects.appserver.WORequest request)
|
java.lang.String |
sessionID()
|
void |
setOriginalResponse(com.webobjects.appserver.WOResponse value)
Sets the original response. |
protected static void |
storeRedirector(ERXComponentActionRedirector redirector)
stores the redirector in the cache. |
java.lang.String |
url()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.log4j.Logger log
protected com.webobjects.appserver.WOResponse originalResponse
protected com.webobjects.appserver.WOResponse redirectionResponse
protected java.lang.String sessionID
protected java.lang.String url
protected static final com.webobjects.foundation.NSMutableDictionary responses
Constructor Detail |
---|
public ERXComponentActionRedirector(ERXComponentActionRedirector.Restorable r)
r
- - Restorable component used to construct a redirectorMethod Detail |
---|
protected static void storeRedirector(ERXComponentActionRedirector redirector)
redirector
- The redirector to store.public static ERXComponentActionRedirector redirectorForRequest(com.webobjects.appserver.WORequest request)
request
- The request
public static void createRedirector(com.webobjects.appserver.WOActionResults results)
results
- public static ERXComponentActionRedirector currentRedirector()
public com.webobjects.appserver.WOResponse redirectionResponse()
public java.lang.String url()
public java.lang.String sessionID()
public com.webobjects.appserver.WOResponse originalResponse()
public void setOriginalResponse(com.webobjects.appserver.WOResponse value)
value
- the original response.
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |