You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Barnes <al...@barnes-home.com> on 2011/04/29 21:16:15 UTC

Action validation is being performed when it shouldn't

Hi all,

I am having a few issues with some code which worked a few days ago but has stopped working for some reason. I have no idea what has changed to cause this but here are the symptoms.

I have an action class called NewSupplierAction which extends ActionSupport and overrides the validate method and execute() methods and also provides a public save() method. The execute method just creates a new Supplier object and returns SUCCESS. This forwards the user to the NewSupplier.jsp page. The execute method is annotated with @SkipValidation because I only want to do the validation when I call the save() method.

For some reason the validate method is being called when the execute() method is invoked. This is happening because the code in the AnnotationValidationInterceptor#doIntercept method doesn't find any annotated methods on the action class and therefore doesn't find the @SkipValidation annotation. I am using the StrutsSpringObject factory and have defined the action in the Spring applicationConfig.xml file and then refer to the action in struts.xml via the Spring bean id.

Can you anyone think of any reason why the DefaultActionProxy doesn't have the expected annotations?

Thanks,

Alex

Re: Action validation is being performed when it shouldn't

Posted by Alex Barnes <al...@barnes-home.com>.
In case anyone is curious this has been solved by removing @Transactional
annotations from all action class methods and moving them on to the methods
on the DAOs.

The presence of the annotation on the action class was resulting in a
JDKDynamicProxy object being passed to the AnnotationValidationInterceptor.
This didn't have the expected @SkipValidation annotation or even the
expected methods on it. By moving the @Transaction annotation off the action
class the AnnotationValidationInterceptor is dealing with the actual
instance of my action with all of the expected annotations and methods.

I'm not sure why the presence of the @Transactional annotations on the
action class caused this problem but it seems to have been solved by moving
them.

Cheers,
Alex

On 29 April 2011 21:09, Alex Barnes <al...@barnes-home.com> wrote:

> Chris,
>
> Thanks for the reply. I think this is the ValidationInterceptor rather than
> the workflow interceptor. The stack trace is as follows:
>
> *ava.lang.NullPointerException*
>
>     com.devcentre.yubi.application.action.NewSupplierAction.validate(NewSupplierAction.java:49)
>     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     java.lang.reflect.Method.invoke(Method.java:597)
>     org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
>     org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
>     $Proxy26.validate(Unknown Source)
>     com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:249)
>     com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:261)
>     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
>
>
> The AnnotationValidationInterceptor extends ValidationInterceptor. The
> reason I think it is related to issues with the Action Proxy is that I first
> noticed this when I created a new action and then the
> AnnotationValidationInterceptor couldn't even find the action method I had
> defined on my action. I then come back and tested this action and found that
> the validate() method was not being called when the execute() method was
> invoked when it wasn't before.
>
> I had all of this working a few days ago. I've spent so long trying to work
> out what is wrong that I have a headache :(
>
> Alex
>
>
>
>
> On 29 Apr 2011, at 20:45, Chris Pratt wrote:
>
> execute
>
>
>

Re: Action validation is being performed when it shouldn't

Posted by Alex Barnes <al...@barnes-home.com>.
Chris,

Thanks for the reply. I think this is the ValidationInterceptor rather than the workflow interceptor. The stack trace is as follows:

ava.lang.NullPointerException
    com.devcentre.yubi.application.action.NewSupplierAction.validate(NewSupplierAction.java:49)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy26.validate(Unknown Source)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:249)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:261)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)

The AnnotationValidationInterceptor extends ValidationInterceptor. The reason I think it is related to issues with the Action Proxy is that I first noticed this when I created a new action and then the AnnotationValidationInterceptor couldn't even find the action method I had defined on my action. I then come back and tested this action and found that the validate() method was not being called when the execute() method was invoked when it wasn't before. 

I had all of this working a few days ago. I've spent so long trying to work out what is wrong that I have a headache :(

Alex




On 29 Apr 2011, at 20:45, Chris Pratt wrote:

> execute


Re: Action validation is being performed when it shouldn't

Posted by Chris Pratt <th...@gmail.com>.
I don't use the those annotations, but from what I can tell, it only affects
the XML validation (validation interceptor) not the programmatic validation
(workflow interceptor).  You can switch from execute to one of the
unvalidated method names (I think input, cancel, and two others I can't
think of at the moment). Or you can add your own methods to the list in the
workflow interceptor.
  (*Chris*)
On Apr 29, 2011 12:08 PM, "Alex Barnes" <al...@barnes-home.com> wrote:
> Hi all,
>
> I am having a few issues with some code which worked a few days ago but
has stopped working for some reason. I have no idea what has changed to
cause this but here are the symptoms.
>
> I have an action class called NewSupplierAction which extends
ActionSupport and overrides the validate method and execute() methods and
also provides a public save() method. The execute method just creates a new
Supplier object and returns SUCCESS. This forwards the user to the
NewSupplier.jsp page. The execute method is annotated with @SkipValidation
because I only want to do the validation when I call the save() method.
>
> For some reason the validate method is being called when the execute()
method is invoked. This is happening because the code in the
AnnotationValidationInterceptor#doIntercept method doesn't find any
annotated methods on the action class and therefore doesn't find the
@SkipValidation annotation. I am using the StrutsSpringObject factory and
have defined the action in the Spring applicationConfig.xml file and then
refer to the action in struts.xml via the Spring bean id.
>
> Can you anyone think of any reason why the DefaultActionProxy doesn't have
the expected annotations?
>
> Thanks,
>
> Alex