On Thursday 29 January 2009 19:49:39 Andy Sykes wrote:
> Hi all,
>
> I've written an interceptor with a PreResultListener that gets the
> action with ActionInvocation.getAction(), then casts it to an
> interface ("Parseable", in this case). This lets me call a particular
> method on the action just prior to the result being rendered.
>
> The action implements Parseable and SessionAware.
>
> When I do the cast, I get an ClassCastException for
> com.opensymphony.xwork2.ActionSupport. If I take it down to one
> interface (SessionAware) and cast the action to it, I still get a CCE.
> What's weirder is I'm pretty sure this code worked on Struts 2.0.11.
>
> Here's a suitably simplified version of what I'm attempting to do:
>
> public String intercept(ActionInvocation invocation) throws Exception {
>          invocation.addPreResultListener(new PreResultListener() {
>                public void beforeResult(ActionInvocation invocation,
> String resultCode) {
>                  Action action = (Action)invocation.getAction();
>                  if (action instanceof Parseable) {
>                      ((Parseable)action).parse();
>                  }
>                }
>      });
>
> Any ideas what the hell is going on here?
>
>

Is it possible that you are using Spring to instantiate your actions via the 
Spring plugin? It would seem that if the action passes the test, then the cast 
is legal. I ask about Spring in case the action is a proxied bean... It comes 
up from time to time that Spring created beans don't always seem to inherit 
every method that you would think... If Spring is in the mix, try having 
Spring use CGLIB... I've had some luck that way, vs. dynamic JDK proxies. 

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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

Reply via email to