You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burton Rhodes <bu...@gmail.com> on 2021/10/07 14:15:43 UTC

When using the ExecuteAndWait interceptor, is it possible to avoid calling prepare / validate methods on reloads?

Through a recent debugging session I realized that when refreshing a "wait"
page during an ExecuteAndWait process, it calls the action's prepare() and
validate() methods each time. For some reason I thought Struts
would immediately identify the "waiting" Action, and if it wasn't finished,
it would return a WAIT result with the running Action at the top of the
stack.  I now realize since the ExecuteAndWait filter is at the end of the
interceptor stack, it obviously doesn't send the WAIT result until all
interceptors have been executed.

That said, in some of my long running actions the prepare() method hits the
database for some rather resource heavy database queries. So if I have an
executeAndWait page showing the progress status (refreshing every 2 seconds
in my case), this seems incredibly inefficient.  Is there a way to avoid
this?  Am I setting up my Action flow incorrectly?

A sample of one of my Action setups in struts.xml:

 <action name="ContactDelete"
class="com.afs.web.struts.action.contact.ContactDeleteAction">
            <interceptor-ref name="myParamsPrepareParamsStack" />
            <result>/struts/contact/contactDelete_modal.jsp</result>
            <result
name="error">/struts/common/error/error_modal.jsp</result>
            <result
name="login">/struts/common/login/login_modal.jsp</result>
</action>
<action name="ContactDelete_delete"
class="com.afs.web.struts.action.contact.ContactDeleteAction"
method="delete">
            <interceptor-ref name="myDefaultStack"/>
            <interceptor-ref name="openSessionExecuteAndWaitInterceptor" >
                <param name="delay">0</param>
            </interceptor-ref>
            <result
name="input">/struts/contact/contactDelete_modal.jsp</result>
            <result
name="wait">/struts/common/progressMonitorWait_modal.jsp</result>
            <result>/struts/common/progressMonitorSuccess_modal.jsp</result>
            <result
name="error">/struts/common/error/error_modal.jsp</result>
            <result
name="login">/struts/common/login/login_modal.jsp</result>
  </action>

Re: When using the ExecuteAndWait interceptor, is it possible to avoid calling prepare / validate methods on reloads?

Posted by Lukasz Lenart <lu...@apache.org>.
pon., 11 paź 2021 o 16:26 Burton Rhodes <bu...@gmail.com> napisał(a):
> Thanks for the reply Lukasz.  I thought about doing something like that,
> but this page
> https://struts.apache.org/core-developers/execute-and-wait-interceptor.html
> mentions the ExecuteAndWait interceptor must be at the end of the stack.  I
> guess you're saying that is not always the case.  I'll give it a try and
> see what happens.  Thanks!

Yes, this can be problematic if you want to have prepare() and
validate() called on initial action execution. If that won't work, we
can implement some sort of skip mechanism, to allow skip processing
given interceptor as there should be any kind of dependency between
interceptors.


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: When using the ExecuteAndWait interceptor, is it possible to avoid calling prepare / validate methods on reloads?

Posted by Burton Rhodes <bu...@gmail.com>.
Thanks for the reply Lukasz.  I thought about doing something like that,
but this page
https://struts.apache.org/core-developers/execute-and-wait-interceptor.html
mentions the ExecuteAndWait interceptor must be at the end of the stack.  I
guess you're saying that is not always the case.  I'll give it a try and
see what happens.  Thanks!

On Mon, Oct 11, 2021 at 1:13 AM Lukasz Lenart <lu...@apache.org>
wrote:

> czw., 7 paź 2021 o 16:16 Burton Rhodes <bu...@gmail.com>
> napisał(a):
> >
> > Through a recent debugging session I realized that when refreshing a
> "wait"
> > page during an ExecuteAndWait process, it calls the action's prepare()
> and
> > validate() methods each time. For some reason I thought Struts
> > would immediately identify the "waiting" Action, and if it wasn't
> finished,
> > it would return a WAIT result with the running Action at the top of the
> > stack.  I now realize since the ExecuteAndWait filter is at the end of
> the
> > interceptor stack, it obviously doesn't send the WAIT result until all
> > interceptors have been executed.
> >
> > That said, in some of my long running actions the prepare() method hits
> the
> > database for some rather resource heavy database queries. So if I have an
> > executeAndWait page showing the progress status (refreshing every 2
> seconds
> > in my case), this seems incredibly inefficient.  Is there a way to avoid
> > this?  Am I setting up my Action flow incorrectly?
> >
> > A sample of one of my Action setups in struts.xml:
> >
> >  <action name="ContactDelete"
> > class="com.afs.web.struts.action.contact.ContactDeleteAction">
> >             <interceptor-ref name="myParamsPrepareParamsStack" />
> >             <result>/struts/contact/contactDelete_modal.jsp</result>
> >             <result
> > name="error">/struts/common/error/error_modal.jsp</result>
> >             <result
> > name="login">/struts/common/login/login_modal.jsp</result>
> > </action>
> > <action name="ContactDelete_delete"
> > class="com.afs.web.struts.action.contact.ContactDeleteAction"
> > method="delete">
> >             <interceptor-ref name="myDefaultStack"/>
> >             <interceptor-ref name="openSessionExecuteAndWaitInterceptor"
> >
> >                 <param name="delay">0</param>
> >             </interceptor-ref>
> >             <result
> > name="input">/struts/contact/contactDelete_modal.jsp</result>
> >             <result
> > name="wait">/struts/common/progressMonitorWait_modal.jsp</result>
> >
>  <result>/struts/common/progressMonitorSuccess_modal.jsp</result>
> >             <result
> > name="error">/struts/common/error/error_modal.jsp</result>
> >             <result
> > name="login">/struts/common/login/login_modal.jsp</result>
> >   </action>
>
> prepare() and validate() are called by different interceptors, which
> means you must put your Exec&Wait interceptor before them in the
> stack. I would use a custom stack for Exec&Wait actions with proper
> order of interceptors. As I see you have a default stack which is
> prepended to Exec&Wait interceptor and that's why those methods are
> called.
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: When using the ExecuteAndWait interceptor, is it possible to avoid calling prepare / validate methods on reloads?

Posted by Lukasz Lenart <lu...@apache.org>.
czw., 7 paź 2021 o 16:16 Burton Rhodes <bu...@gmail.com> napisał(a):
>
> Through a recent debugging session I realized that when refreshing a "wait"
> page during an ExecuteAndWait process, it calls the action's prepare() and
> validate() methods each time. For some reason I thought Struts
> would immediately identify the "waiting" Action, and if it wasn't finished,
> it would return a WAIT result with the running Action at the top of the
> stack.  I now realize since the ExecuteAndWait filter is at the end of the
> interceptor stack, it obviously doesn't send the WAIT result until all
> interceptors have been executed.
>
> That said, in some of my long running actions the prepare() method hits the
> database for some rather resource heavy database queries. So if I have an
> executeAndWait page showing the progress status (refreshing every 2 seconds
> in my case), this seems incredibly inefficient.  Is there a way to avoid
> this?  Am I setting up my Action flow incorrectly?
>
> A sample of one of my Action setups in struts.xml:
>
>  <action name="ContactDelete"
> class="com.afs.web.struts.action.contact.ContactDeleteAction">
>             <interceptor-ref name="myParamsPrepareParamsStack" />
>             <result>/struts/contact/contactDelete_modal.jsp</result>
>             <result
> name="error">/struts/common/error/error_modal.jsp</result>
>             <result
> name="login">/struts/common/login/login_modal.jsp</result>
> </action>
> <action name="ContactDelete_delete"
> class="com.afs.web.struts.action.contact.ContactDeleteAction"
> method="delete">
>             <interceptor-ref name="myDefaultStack"/>
>             <interceptor-ref name="openSessionExecuteAndWaitInterceptor" >
>                 <param name="delay">0</param>
>             </interceptor-ref>
>             <result
> name="input">/struts/contact/contactDelete_modal.jsp</result>
>             <result
> name="wait">/struts/common/progressMonitorWait_modal.jsp</result>
>             <result>/struts/common/progressMonitorSuccess_modal.jsp</result>
>             <result
> name="error">/struts/common/error/error_modal.jsp</result>
>             <result
> name="login">/struts/common/login/login_modal.jsp</result>
>   </action>

prepare() and validate() are called by different interceptors, which
means you must put your Exec&Wait interceptor before them in the
stack. I would use a custom stack for Exec&Wait actions with proper
order of interceptors. As I see you have a default stack which is
prepended to Exec&Wait interceptor and that's why those methods are
called.


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org