In your interceptor, you're replacing the logic from the
DefaultWorkflowInterceptor with your own.  What you really want to do is
perform your work, then allow it to do it's job.  So, instead of return
invocation.invoke();, try  return super.intercept(invocation); and see if
that does more what you are looking for.
  (*Chris*)

On Tue, Jun 7, 2011 at 9:32 PM, Nikul Suthar <nikulsut...@gmail.com> wrote:

> Hi There,
>
> I'm pretty new to using Struts 2 for developing a web application. So I
> would be very thankful if someone can clear out this roadblock for me.
>
> I'm trying to write some custom validation code in method *public void
> validate()* in the Action class. I also created an interceptor extending *
> DefaultWorkflowInterceptor* checking for session object validity. But since
> I implemented the interceptor my validate method does not get executed at
> all. I need the validate method to be executed to implement custom field
> validations every time the request is received. Since I'm new to using
> Struts 2 this is the best design I could come up with. Your help in making
> the validate method execute every time the request is received without
> removing the interceptor will be highly appreciated. Following is my code:
>
> *ShowChangePassword2Of2Action*
> *
> *
> public class ShowChangePassword2Of2Action extends ActionSupport implements
> Validateable{
>    [Field variables]
>
>    public String show(){
>        [My business logic]
>    }
>
>    public void validate(){
>        [My validation logic]
>    }
>
>    [Field variables getters and setters]
> }
>
>
>
> *SessionInterceptor*
> *
> *
> public class SessionInterceptor extends DefaultWorkflowInterceptor{
>    private static final long serialVersionUID = 1L;
>
>    public String intercept(ActionInvocation invocation) throws Exception {
>    ActionContext context = invocation.getInvocationContext();
>    Map<String, Object> sessionMap = context.getSession();
>    if(sessionMap == null || sessionMap.isEmpty()){
>     System.out.println("Session expired...");
>     return "sessionExpired";
>    }//if
>    else{
>    return invocation.invoke();
>    }//else
>    }
>
>    public void destroy() {
>        System.out.println("Destroying Session Interceptor...");
>    }
>    public void init() {
>        System.out.println("Initializing Session Interceptor...");
>    }
> }
>
>
>
> *struts.xml*
> *
> *
> <struts>
> <package name="default" extends="struts-default">
> <result-types>
> <result-type name="tiles"
> class="org.apache.struts2.views.tiles.TilesResult"
> />
> </result-types>
>  <interceptors>
>     <interceptor name="sessionInterceptor"
> class="org.zssinfo.interceptor.SessionInterceptor"></interceptor>
>    <interceptor-stack name="sessionInterceptorStack">
>        <interceptor-ref name="sessionInterceptor" />
>    </interceptor-stack>
> </interceptors>
>  <global-results>
> <result name="sessionExpired" type="tiles">welcome</result>
> </global-results>
>  <action name="*ChangePassword2Of2" method="{1}"
> class="org.zssinfo.action.ShowChangePassword2Of2Action">
> <interceptor-ref name="sessionInterceptorStack"></interceptor-ref>
> <result name="success" type="tiles">showChangePassword2Of2</result>
> <result name="showChangePassword2Of2Error" type="tiles">errorPage</result>
> <result name="input" type="tiles">showChangePassword1Of2</result>
> </action>
> </package>
> </struts>
>
> Thank you very much in advance.
>
> Thanks,
> Nikul
>

Reply via email to