[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: How can I add ActionErrors when do the interceptor's intercept() method?
From:       "M.Liang Liu " <patriotlml () gmail ! com>
Date:       2007-07-17 12:15:23
Message-ID: 852ed41d0707170515r717c3439w87e05ddff7e99d63 () mail ! gmail ! com
[Download RAW message or body]


Thanks for you quick reply,Nuwan.

yeah,ur code works and action-error should be add to the original action(I
tested).
However,I set my global result in my default package,and when the invalid
action accessing was intercepted,the browser was redirect to the login page.
It's strange that the action-error did NOT display.I am sure that my
interceptor has been configured correctly and the actionError has been add
to the very action.
I guess the global result whose type is "redirect" cause this problem,but am
not sure.

So,I define my login result as dispatch,which is default, it works.My global
result is follwing:
--------------------------------------------------------------------------------
<global-results>
            <result name="error">/error.jsp</result>
            <result name="login">/common/login.jsp</result>
            <result name="invalid.token">/error.jsp</result>
        </global-results>
----------------------------------------------------------------------------------

Does it work?yes.action error has been add and can display correctly.
The problem is that I can NOT use redirect type any more.As a result,the
doLogin action---the login form's action---can not mapped,as  the namespace
now is still the invalid action's.
eg.I access :http://localhost:8080/myapp/kms/showNews.tbs before logged in
Then access was intercepted and dispatched to :
http://localhost:8080/myapp/common/login.jsp
so I logged.
The form was submitted  to http://localhost:8080/myapp/kms/doLogin.tbs
which should be:http://localhost:8080/myapp/common/doLogin.tbs

Any comment?

Thanks a lot.
On 7/18/07, Nuwan Chandrasoma <mymailnot@gmail.com> wrote:
> 
> Hi,
> 
> hope this code will help you.
> 
> Object action = invocation.getAction ();
> if (action instanceof com.opensymphony.xwork2.ValidationAware) {
> ((com.opensymphony.xwork2.ValidationAware) action).addActionError
> ("Username or password incorrect.");
> }
> 
> Thanks,
> 
> Nuwan.
> 
> ----- Original Message -----
> From: "M.Liang Liu" <patriotlml@gmail.com>
> To: <user@struts.apache.org>
> Sent: Tuesday, July 17, 2007 9:49 AM
> Subject: How can I add ActionErrors when do the interceptor's intercept()
> method?
> 
> 
> > 
> > Hi,all
> > I've got a problem when I put my own interceptors in my app:
> > I write an interceptor to authenticate whether the user access the
> current
> > page or action has logged in.
> > I write the code in the following style(refer to the mailreader
> example):
> > --------------------------------------------------------------------
> > ......
> > public String intercept(ActionInvocation actionInvocation) throws
> > Exception
> > {
> > Map session = actionInvocation.getInvocationContext().getSession();
> > User user = (User) session.get(Constants.USER_KEY);
> > boolean isAuthenticated = (null != user);
> > if (isAuthenticated) {
> > return actionInvocation.invoke();
> > } else {
> > //how to add actionErrors here?
> > return Action.LOGIN;
> > }
> > .....
> > 
> > --------------------------------------------------------------------
> > The question is that :how can I addActionErrors to the interceptor,so
> that
> > when the invalid action---namelly not logged in---was redirected to the
> > login page,some actionErrors messages like "You are not logged in" can
> > display.
> > 
> > I notice that I can put cite addActionErrors("You are not logged in");
> in
> > my
> > action class,however,I do NOT have any hint how to add action errors in
> my
> > interceptor.
> > Just or can't?
> > 
> > Any comment would be appreciated.
> > --
> > View this message in context:
> > 
> http://www.nabble.com/How-can-I-add-ActionErrors-when-do-the-interceptor%27s-intercept%28%29-method--tf4095868.html#a11646263
> 
> > Sent from the Struts - User mailing list archive at Nabble.com.
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
              ------M.Liang Liu



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic