Skip to content

Commit

Permalink
use context.directActionURLForActionNamed() for URL generation of dir…
Browse files Browse the repository at this point in the history
…ect actions and add a flag to include sessionID
  • Loading branch information
darkv authored and Pascal Robert committed Apr 30, 2012
1 parent ecf4306 commit 4e2898a
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.webobjects.appserver.WOResponse;
import com.webobjects.appserver.WOSession;
import com.webobjects.foundation.NSDictionary;
import com.webobjects.foundation.NSMutableDictionary;

import er.extensions.appserver.ajax.ERXAjaxApplication;
import er.extensions.foundation.ERXMutableURL;
Expand All @@ -26,6 +27,7 @@ public class ERXRedirect extends WOComponent {
private String _requestHandlerKey;
private String _requestHandlerPath;
private Boolean _secure;
private boolean _includeSessionID;

private String _directActionClass;
private String _directActionName;
Expand All @@ -36,6 +38,7 @@ public class ERXRedirect extends WOComponent {
public ERXRedirect(WOContext context) {
super(context);
_originalComponent = context.page();
_includeSessionID = false;
}

/**
Expand All @@ -48,6 +51,17 @@ public ERXRedirect(WOContext context) {
public void setSecure(boolean secure) {
_secure = Boolean.valueOf(secure);
}

/**
* Sets whether or not a direct action URL should contain the session ID.
* This defaults to <code>false</code> to maintain backward compatibility.
*
* @param includeSessionID
* whether or not a sessionID should be included
*/
public void setIncludeSessionID(boolean includeSessionID) {
_includeSessionID = includeSessionID;
}

/**
* Sets the request handler key to redirect to. You typically want to also
Expand Down Expand Up @@ -150,6 +164,19 @@ protected String queryParametersString() {
}
return queryParametersString;
}

protected NSDictionary<String, Object> directActionQueryParameters() {
NSMutableDictionary<String, Object> params = null;
if (_queryParameters != null) {
params = (NSMutableDictionary<String, Object>) _queryParameters.mutableClone();
} else {
params = new NSMutableDictionary<String, Object>();
}
if (!_includeSessionID) {
params.takeValueForKey(Boolean.FALSE.toString(), WOApplication.application().sessionIdKey());
}
return params;
}

@Override
public void appendToResponse(WOResponse response, WOContext context) {
Expand Down Expand Up @@ -221,7 +248,7 @@ else if (_directActionName != null) {
else {
requestHandlerPath = _directActionName;
}
url = context._urlWithRequestHandlerKey(WOApplication.application().directActionRequestHandlerKey(), requestHandlerPath, queryParametersString(), secure);
url = context.directActionURLForActionNamed(requestHandlerPath, directActionQueryParameters(), secure, 0, false);
}
else {
throw new IllegalStateException("You must provide a component, url, requestHandlerKey, or directActionName to this ERXRedirect.");
Expand Down

0 comments on commit 4e2898a

Please sign in to comment.