Change Action Method In Interceptor

2015-03-11 Thread R Veach
Hi,

I know it is possible to limit struts to specific methods using the
MethodFilterInterceptor, and to change the execute method in the config or
form declaration using the method attribute.

Is it possible to have an interceptor change which method would be executed
in the action? I see I can get the method name using
invocation.getProxy().getMethod(), but I can't find any setter.

One reason I want to do this is to build submit and first time in logic
without defining it everywhere for every page and have an interceptor do
the work for me.
I would identify if it is first time or submit based on request to see if
it is GET or POST.
I could call the methods directly from the interceptor since I have the
action instance, but that would bypass the rest of the interceptor chain
and would require this interceptor to always be last in the list.

Here is an example of what I was planning:

//
if (isFirstTime(request)) {
if (action instanceof FirstTimeLogic) {
   invocation.getProxy().setMethod(executeFirstTimeInLogic);
}
} else {
if (action instanceof SubmitLogic) {
invocation.getProxy().setMethod(executeSubmitLogic);
}
}

return invocation.invoke();


Re: Change Action Method In Interceptor

2015-03-11 Thread Lukasz Lenart
2015-03-11 16:29 GMT+01:00 R Veach rveac...@gmail.com:
 Hi,

 I know it is possible to limit struts to specific methods using the
 MethodFilterInterceptor, and to change the execute method in the config or
 form declaration using the method attribute.

 Is it possible to have an interceptor change which method would be executed
 in the action? I see I can get the method name using
 invocation.getProxy().getMethod(), but I can't find any setter.

There is a reason for that - other interceptors can based on that ;-)

 One reason I want to do this is to build submit and first time in logic
 without defining it everywhere for every page and have an interceptor do
 the work for me.
 I would identify if it is first time or submit based on request to see if
 it is GET or POST.
 I could call the methods directly from the interceptor since I have the
 action instance, but that would bypass the rest of the interceptor chain
 and would require this interceptor to always be last in the list.

 Here is an example of what I was planning:

 //
 if (isFirstTime(request)) {
 if (action instanceof FirstTimeLogic) {
invocation.getProxy().setMethod(executeFirstTimeInLogic);
 }
 } else {
 if (action instanceof SubmitLogic) {
 invocation.getProxy().setMethod(executeSubmitLogic);
 }
 }

 return invocation.invoke();

The best option is to implement your own version of ActionProxyFactory
and ActionProxy - and used them instead of default one.


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

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