Created
July 9, 2014 15:37
-
-
Save lucascs/ee52689f39f734167ce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Specializes | |
@RequestScoped | |
public class CidLogicResult extends DefaultLogicResult { | |
private MutableRequest request; | |
public CidLogicResult(...., MutableRequest request) { | |
super(....); | |
this.request = request; | |
} | |
@Override | |
public <T> T redirectTo(final Class<T> type) { | |
logger.debug("redirecting to class {}", type.getSimpleName()); | |
return proxifier.proxify(type, new MethodInvocation<T>() { | |
@Override | |
public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { | |
checkArgument(acceptsHttpGet(method), "Your logic method must accept HTTP GET method if you want to redirect to it"); | |
try { | |
String url = router.urlFor(type, method, args); | |
String path = request.getContextPath() + url; | |
if (request.getParameter("cid") != null) { | |
path = path + "?cid=" + request.getParameter("cid"); | |
} | |
includeParametersInFlash(type, method, args); | |
logger.debug("redirecting to {}", path); | |
response.sendRedirect(path); | |
return null; | |
} catch (IOException e) { | |
throw new ProxyInvocationException(e); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment