Struts 2 how to display messages saved in a Interceptor which would redirec to another action?
Posted
by
mui13
on Stack Overflow
See other posts from Stack Overflow
or by mui13
Published on 2011-01-08T02:07:11Z
Indexed on
2011/01/08
17:53 UTC
Read the original article
Hit count: 301
in my interceptor, if user doesn't have enough right, there would be a warn message:
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext actionContext = invocation.getInvocationContext();
Map<String, Object> sessionMap = actionContext.getSession();
User loginUser = (User) sessionMap.get("user");
Object action = invocation.getAction();
if (loginUser != null && loginUser.getRole().getId() != Constant.AUTHORITY_ADMIN) {
((ValidationAware) action).addFieldError("user.authority",
((DefaultAction) action).getText("user.action.authority.not.enough"));
return DefaultAction.HOME_PAGE;
}
return invocation.invoke();
}
then, it would redirect to "HOME_PAGE" action, if success, display information in the jsp. So how to display the warn message?
i have used two interceptors configed in strust.xml, for admin right requirment:
<interceptor-stack name="authorityStack">
<interceptor-ref name="authority" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
</interceptor-stack>
default is:
<interceptor-stack name="default">
<interceptor-ref name="login" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
</interceptor-stack>
© Stack Overflow or respective owner