You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Kiley <jh...@summa-tech.com> on 2008/04/30 21:47:46 UTC

Struts 2 Annotation Validation Problem

Hi folks,

I've run into a problem with Struts 2 validation annotations.

In short -- I have a VisitorFieldValidator on an action POJO named
ProductDetailAction.  I have RequiredFieldValidator and
RequiredStringValidator on one field within the "visited" object.

Now -- ProductDetailAction did not (originally) inherit from ActionSupport.
I could see validation errors cropping up in my log, but my save() method
was still executing, because , as I understand it, without ActionSupport (or
ValidationAware) there was no way for Struts to redirect my action back to
my input() method when it found a validation error.

If I change the hierarchy so that ProductDetailAction DOES inherit,
indirectly, from ActionSupport, I can't even get to my input() method -- my
productDetail JSP doesn't render. Instead I get the following exception:

java.lang.IllegalArgumentException: The input() is not defined in action
class $Proxy99
    at
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:412)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
(...)

I get the same exception if I simply implement ValidationAware in the same
way that ActionSupport does.

I'm including relevant snippets of ProductDetailAction, Product, and
struts.xml below.  Does anyone have any insight as to why this might be
happening?  I'm stumped, and so are my coworkers.  Thanks.

Jim

-----
ProductDetailAction.java
-----
@Validation
public class ProductDetailAction extends FormularyDetailAction { // note:
FormularyDetailAction extends ActionSupport
// snippery

    @Override
    @SkipValidation
    public String input() throws Exception {
        if(id==null || id < 1) {
            this.product = new Product();
        } else {
            this.product = formularyBso.fetchProduct(this.id);
        }
        return Action.INPUT;
    }

    @VisitorFieldValidator(message="")
    public Product getProduct() {
        return product;
    }
// snippery
}
-----
Product.java
-----
@Entity
@Table(name="myrespironics.p_product_versions")
@Validation
public class Product extends FormularyProduct {
    //snip
@RequiredFieldValidator(message="Please enter a value.")
    @RequiredStringValidator(message="Please enter a value.")
    public String getName() {
        return name;
    }
//snip
}
-----
struts.xml
-----
<struts>
    <package name="user" extends="struts-default">
          <interceptors>
            <interceptor-stack name="myInterceptors">
                <interceptor-ref name="exception"/>
                <interceptor-ref name="alias"/>
                <interceptor-ref name="params"/>
                <interceptor-ref name="servletConfig"/>
                <interceptor-ref name="prepare" />
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="chain"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="staticParams"/>
                <interceptor-ref name="params"/>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">input,back,cancel</param>
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">input,back,cancel</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="myInterceptors"/>
        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <action name="productDetail" class="productDetailAction"
method="input">
            <result name="success"
type="redirect-action">productList</result>
            <result
name="input">/WEB-INF/secure/formulary/productDetail.jsp</result>
            <result name="success-subcategory" type="redirect-action">
                <param name="actionName">subcategoryDetail</param>
                <param name="parse">true</param>
                <param name="id">${subcategoryId}</param>
            </result>
        </action>

            </package>
</struts>
-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com

Re: Struts 2 Annotation Validation Problem

Posted by mctdeveloper <ms...@yahoo.com>.
Just see the below link for usage of Annotations in validation,
Hope might be useful

http://intricatetips.blogspot.com
-- 
View this message in context: http://www.nabble.com/Struts-2-Annotation-Validation-Problem-tp16990235p19592822.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 Annotation Validation Problem

Posted by Wes Wannemacher <we...@wantii.com>.
I could be wrong in my assumption, but I became suspicious when the
action class wasn't in the stacktrace... 


On Tue, 2008-05-06 at 20:48 -0400, Jim Kiley wrote:
> It's weird and confusing that inherited methods don't make it into the proxy
> class.  Took me an age to figure it out, in no small part because I couldn't
> find an easy way to inspect the proxy class's methods.  My workaround was to
> eliminate the @Transactional annotation entirely, and I'm hoping that
> doesn't bite me later.
> 
> jk
> 
> On Tue, May 6, 2008 at 8:38 PM, Wes Wannemacher <we...@wantii.com> wrote:
> 
> > Sorry I didn't catch this earlier, but I had the exact same problem. It
> > would seem that when you use Spring's @Transactional annnotation, the
> > class gets proxied... Which I would think is okay, except for the fact
> > that inherited methods (such as ActionSupport.input()) do not make it
> > into the proxied class. :(
> >
> > For me, I simply re-factored the @Transactional method out into a
> > service class that I have injected into my Action class. IMO, it's ugly,
> > but it works.
> >
> > -Wes
> >
> > On Tue, 2008-05-06 at 17:36 -0400, Jim Kiley wrote:
> > > I solved this problem and I figure that nabble might want to record the
> > end
> > > reason for the bug.
> > >
> > > Another method entirely, elsewhere on ProductDetailAction, had a
> > > @Transactional annotation.  It didn't need one -- I was using injected
> > > transaction management and the OpenEntityManagerInViewFilter.  Why the
> > error
> > > message below was generated, instead of "hey dummy, don't use
> > @Transactional
> > > in this context," is beyond me, but at least it's fixed.
> > >
> > > jk
> > >
> > > On Wed, Apr 30, 2008 at 3:47 PM, Jim Kiley <jh...@summa-tech.com>
> > wrote:
> > >
> > > > Hi folks,
> > > >
> > > > I've run into a problem with Struts 2 validation annotations.
> > > >
> > > > In short -- I have a VisitorFieldValidator on an action POJO named
> > > > ProductDetailAction.  I have RequiredFieldValidator and
> > > > RequiredStringValidator on one field within the "visited" object.
> > > >
> > > > Now -- ProductDetailAction did not (originally) inherit from
> > > > ActionSupport.  I could see validation errors cropping up in my log,
> > but my
> > > > save() method was still executing, because , as I understand it,
> > without
> > > > ActionSupport (or ValidationAware) there was no way for Struts to
> > redirect
> > > > my action back to my input() method when it found a validation error.
> > > >
> > > > If I change the hierarchy so that ProductDetailAction DOES inherit,
> > > > indirectly, from ActionSupport, I can't even get to my input() method
> > -- my
> > > > productDetail JSP doesn't render. Instead I get the following
> > exception:
> > > >
> > > > java.lang.IllegalArgumentException: The input() is not defined in
> > action
> > > > class $Proxy99
> > > >     at
> > > >
> > com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:412)
> > > >     at
> > > >
> > com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
> > > >     at
> > > >
> > com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
> > > >     at
> > > >
> > com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
> > > > (...)
> > > >
> > > > I get the same exception if I simply implement ValidationAware in the
> > same
> > > > way that ActionSupport does.
> > > >
> > > > I'm including relevant snippets of ProductDetailAction, Product, and
> > > > struts.xml below.  Does anyone have any insight as to why this might
> > be
> > > > happening?  I'm stumped, and so are my coworkers.  Thanks.
> > > >
> > > > Jim
> > > >
> > > > -----
> > > > ProductDetailAction.java
> > > > -----
> > > > @Validation
> > > > public class ProductDetailAction extends FormularyDetailAction { //
> > note:
> > > > FormularyDetailAction extends ActionSupport
> > > > // snippery
> > > >
> > > >     @Override
> > > >     @SkipValidation
> > > >     public String input() throws Exception {
> > > >         if(id==null || id < 1) {
> > > >             this.product = new Product();
> > > >         } else {
> > > >             this.product = formularyBso.fetchProduct(this.id);
> > > >         }
> > > >         return Action.INPUT;
> > > >     }
> > > >
> > > >     @VisitorFieldValidator(message="")
> > > >     public Product getProduct() {
> > > >         return product;
> > > >     }
> > > > // snippery
> > > > }
> > > > -----
> > > > Product.java
> > > > -----
> > > > @Entity
> > > > @Table(name="myrespironics.p_product_versions")
> > > > @Validation
> > > > public class Product extends FormularyProduct {
> > > >     //snip
> > > > @RequiredFieldValidator(message="Please enter a value.")
> > > >     @RequiredStringValidator(message="Please enter a value.")
> > > >     public String getName() {
> > > >         return name;
> > > >     }
> > > > //snip
> > > > }
> > > > -----
> > > > struts.xml
> > > > -----
> > > > <struts>
> > > >     <package name="user" extends="struts-default">
> > > >           <interceptors>
> > > >             <interceptor-stack name="myInterceptors">
> > > >                 <interceptor-ref name="exception"/>
> > > >                 <interceptor-ref name="alias"/>
> > > >                 <interceptor-ref name="params"/>
> > > >                 <interceptor-ref name="servletConfig"/>
> > > >                 <interceptor-ref name="prepare" />
> > > >                 <interceptor-ref name="i18n"/>
> > > >                 <interceptor-ref name="chain"/>
> > > >                 <interceptor-ref name="modelDriven"/>
> > > >                 <interceptor-ref name="fileUpload"/>
> > > >                 <interceptor-ref name="checkbox"/>
> > > >                 <interceptor-ref name="staticParams"/>
> > > >                 <interceptor-ref name="params"/>
> > > >                 <interceptor-ref name="conversionError"/>
> > > >                 <interceptor-ref name="validation">
> > > >                     <param
> > name="excludeMethods">input,back,cancel</param>
> > > >                 </interceptor-ref>
> > > >                 <interceptor-ref name="workflow">
> > > >                     <param
> > name="excludeMethods">input,back,cancel</param>
> > > >                 </interceptor-ref>
> > > >             </interceptor-stack>
> > > >         </interceptors>
> > > >
> > > >         <default-interceptor-ref name="myInterceptors"/>
> > > >         <global-results>
> > > >             <result name="error">/error.jsp</result>
> > > >         </global-results>
> > > >
> > > >         <action name="productDetail" class="productDetailAction"
> > > > method="input">
> > > >             <result name="success"
> > > > type="redirect-action">productList</result>
> > > >             <result
> > > > name="input">/WEB-INF/secure/formulary/productDetail.jsp</result>
> > > >             <result name="success-subcategory" type="redirect-action">
> > > >                 <param name="actionName">subcategoryDetail</param>
> > > >                 <param name="parse">true</param>
> > > >                 <param name="id">${subcategoryId}</param>
> > > >             </result>
> > > >         </action>
> > > >
> > > >             </package>
> > > > </struts>
> > > > --
> > > > Jim Kiley
> > > > Technical Consultant | Summa
> > > > [p] 412.258.3346 [m] 412.445.1729
> > > > http://www.summa-tech.com
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 


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


Re: Struts 2 Annotation Validation Problem

Posted by Jim Kiley <jh...@summa-tech.com>.
It's weird and confusing that inherited methods don't make it into the proxy
class.  Took me an age to figure it out, in no small part because I couldn't
find an easy way to inspect the proxy class's methods.  My workaround was to
eliminate the @Transactional annotation entirely, and I'm hoping that
doesn't bite me later.

jk

On Tue, May 6, 2008 at 8:38 PM, Wes Wannemacher <we...@wantii.com> wrote:

> Sorry I didn't catch this earlier, but I had the exact same problem. It
> would seem that when you use Spring's @Transactional annnotation, the
> class gets proxied... Which I would think is okay, except for the fact
> that inherited methods (such as ActionSupport.input()) do not make it
> into the proxied class. :(
>
> For me, I simply re-factored the @Transactional method out into a
> service class that I have injected into my Action class. IMO, it's ugly,
> but it works.
>
> -Wes
>
> On Tue, 2008-05-06 at 17:36 -0400, Jim Kiley wrote:
> > I solved this problem and I figure that nabble might want to record the
> end
> > reason for the bug.
> >
> > Another method entirely, elsewhere on ProductDetailAction, had a
> > @Transactional annotation.  It didn't need one -- I was using injected
> > transaction management and the OpenEntityManagerInViewFilter.  Why the
> error
> > message below was generated, instead of "hey dummy, don't use
> @Transactional
> > in this context," is beyond me, but at least it's fixed.
> >
> > jk
> >
> > On Wed, Apr 30, 2008 at 3:47 PM, Jim Kiley <jh...@summa-tech.com>
> wrote:
> >
> > > Hi folks,
> > >
> > > I've run into a problem with Struts 2 validation annotations.
> > >
> > > In short -- I have a VisitorFieldValidator on an action POJO named
> > > ProductDetailAction.  I have RequiredFieldValidator and
> > > RequiredStringValidator on one field within the "visited" object.
> > >
> > > Now -- ProductDetailAction did not (originally) inherit from
> > > ActionSupport.  I could see validation errors cropping up in my log,
> but my
> > > save() method was still executing, because , as I understand it,
> without
> > > ActionSupport (or ValidationAware) there was no way for Struts to
> redirect
> > > my action back to my input() method when it found a validation error.
> > >
> > > If I change the hierarchy so that ProductDetailAction DOES inherit,
> > > indirectly, from ActionSupport, I can't even get to my input() method
> -- my
> > > productDetail JSP doesn't render. Instead I get the following
> exception:
> > >
> > > java.lang.IllegalArgumentException: The input() is not defined in
> action
> > > class $Proxy99
> > >     at
> > >
> com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:412)
> > >     at
> > >
> com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
> > >     at
> > >
> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
> > >     at
> > >
> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
> > > (...)
> > >
> > > I get the same exception if I simply implement ValidationAware in the
> same
> > > way that ActionSupport does.
> > >
> > > I'm including relevant snippets of ProductDetailAction, Product, and
> > > struts.xml below.  Does anyone have any insight as to why this might
> be
> > > happening?  I'm stumped, and so are my coworkers.  Thanks.
> > >
> > > Jim
> > >
> > > -----
> > > ProductDetailAction.java
> > > -----
> > > @Validation
> > > public class ProductDetailAction extends FormularyDetailAction { //
> note:
> > > FormularyDetailAction extends ActionSupport
> > > // snippery
> > >
> > >     @Override
> > >     @SkipValidation
> > >     public String input() throws Exception {
> > >         if(id==null || id < 1) {
> > >             this.product = new Product();
> > >         } else {
> > >             this.product = formularyBso.fetchProduct(this.id);
> > >         }
> > >         return Action.INPUT;
> > >     }
> > >
> > >     @VisitorFieldValidator(message="")
> > >     public Product getProduct() {
> > >         return product;
> > >     }
> > > // snippery
> > > }
> > > -----
> > > Product.java
> > > -----
> > > @Entity
> > > @Table(name="myrespironics.p_product_versions")
> > > @Validation
> > > public class Product extends FormularyProduct {
> > >     //snip
> > > @RequiredFieldValidator(message="Please enter a value.")
> > >     @RequiredStringValidator(message="Please enter a value.")
> > >     public String getName() {
> > >         return name;
> > >     }
> > > //snip
> > > }
> > > -----
> > > struts.xml
> > > -----
> > > <struts>
> > >     <package name="user" extends="struts-default">
> > >           <interceptors>
> > >             <interceptor-stack name="myInterceptors">
> > >                 <interceptor-ref name="exception"/>
> > >                 <interceptor-ref name="alias"/>
> > >                 <interceptor-ref name="params"/>
> > >                 <interceptor-ref name="servletConfig"/>
> > >                 <interceptor-ref name="prepare" />
> > >                 <interceptor-ref name="i18n"/>
> > >                 <interceptor-ref name="chain"/>
> > >                 <interceptor-ref name="modelDriven"/>
> > >                 <interceptor-ref name="fileUpload"/>
> > >                 <interceptor-ref name="checkbox"/>
> > >                 <interceptor-ref name="staticParams"/>
> > >                 <interceptor-ref name="params"/>
> > >                 <interceptor-ref name="conversionError"/>
> > >                 <interceptor-ref name="validation">
> > >                     <param
> name="excludeMethods">input,back,cancel</param>
> > >                 </interceptor-ref>
> > >                 <interceptor-ref name="workflow">
> > >                     <param
> name="excludeMethods">input,back,cancel</param>
> > >                 </interceptor-ref>
> > >             </interceptor-stack>
> > >         </interceptors>
> > >
> > >         <default-interceptor-ref name="myInterceptors"/>
> > >         <global-results>
> > >             <result name="error">/error.jsp</result>
> > >         </global-results>
> > >
> > >         <action name="productDetail" class="productDetailAction"
> > > method="input">
> > >             <result name="success"
> > > type="redirect-action">productList</result>
> > >             <result
> > > name="input">/WEB-INF/secure/formulary/productDetail.jsp</result>
> > >             <result name="success-subcategory" type="redirect-action">
> > >                 <param name="actionName">subcategoryDetail</param>
> > >                 <param name="parse">true</param>
> > >                 <param name="id">${subcategoryId}</param>
> > >             </result>
> > >         </action>
> > >
> > >             </package>
> > > </struts>
> > > --
> > > Jim Kiley
> > > Technical Consultant | Summa
> > > [p] 412.258.3346 [m] 412.445.1729
> > > http://www.summa-tech.com
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com

Re: Struts 2 Annotation Validation Problem

Posted by Wes Wannemacher <we...@wantii.com>.
Sorry I didn't catch this earlier, but I had the exact same problem. It
would seem that when you use Spring's @Transactional annnotation, the
class gets proxied... Which I would think is okay, except for the fact
that inherited methods (such as ActionSupport.input()) do not make it
into the proxied class. :(

For me, I simply re-factored the @Transactional method out into a
service class that I have injected into my Action class. IMO, it's ugly,
but it works. 

-Wes

On Tue, 2008-05-06 at 17:36 -0400, Jim Kiley wrote:
> I solved this problem and I figure that nabble might want to record the end
> reason for the bug.
> 
> Another method entirely, elsewhere on ProductDetailAction, had a
> @Transactional annotation.  It didn't need one -- I was using injected
> transaction management and the OpenEntityManagerInViewFilter.  Why the error
> message below was generated, instead of "hey dummy, don't use @Transactional
> in this context," is beyond me, but at least it's fixed.
> 
> jk
> 
> On Wed, Apr 30, 2008 at 3:47 PM, Jim Kiley <jh...@summa-tech.com> wrote:
> 
> > Hi folks,
> >
> > I've run into a problem with Struts 2 validation annotations.
> >
> > In short -- I have a VisitorFieldValidator on an action POJO named
> > ProductDetailAction.  I have RequiredFieldValidator and
> > RequiredStringValidator on one field within the "visited" object.
> >
> > Now -- ProductDetailAction did not (originally) inherit from
> > ActionSupport.  I could see validation errors cropping up in my log, but my
> > save() method was still executing, because , as I understand it, without
> > ActionSupport (or ValidationAware) there was no way for Struts to redirect
> > my action back to my input() method when it found a validation error.
> >
> > If I change the hierarchy so that ProductDetailAction DOES inherit,
> > indirectly, from ActionSupport, I can't even get to my input() method -- my
> > productDetail JSP doesn't render. Instead I get the following exception:
> >
> > java.lang.IllegalArgumentException: The input() is not defined in action
> > class $Proxy99
> >     at
> > com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:412)
> >     at
> > com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
> >     at
> > com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
> >     at
> > com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
> > (...)
> >
> > I get the same exception if I simply implement ValidationAware in the same
> > way that ActionSupport does.
> >
> > I'm including relevant snippets of ProductDetailAction, Product, and
> > struts.xml below.  Does anyone have any insight as to why this might be
> > happening?  I'm stumped, and so are my coworkers.  Thanks.
> >
> > Jim
> >
> > -----
> > ProductDetailAction.java
> > -----
> > @Validation
> > public class ProductDetailAction extends FormularyDetailAction { // note:
> > FormularyDetailAction extends ActionSupport
> > // snippery
> >
> >     @Override
> >     @SkipValidation
> >     public String input() throws Exception {
> >         if(id==null || id < 1) {
> >             this.product = new Product();
> >         } else {
> >             this.product = formularyBso.fetchProduct(this.id);
> >         }
> >         return Action.INPUT;
> >     }
> >
> >     @VisitorFieldValidator(message="")
> >     public Product getProduct() {
> >         return product;
> >     }
> > // snippery
> > }
> > -----
> > Product.java
> > -----
> > @Entity
> > @Table(name="myrespironics.p_product_versions")
> > @Validation
> > public class Product extends FormularyProduct {
> >     //snip
> > @RequiredFieldValidator(message="Please enter a value.")
> >     @RequiredStringValidator(message="Please enter a value.")
> >     public String getName() {
> >         return name;
> >     }
> > //snip
> > }
> > -----
> > struts.xml
> > -----
> > <struts>
> >     <package name="user" extends="struts-default">
> >           <interceptors>
> >             <interceptor-stack name="myInterceptors">
> >                 <interceptor-ref name="exception"/>
> >                 <interceptor-ref name="alias"/>
> >                 <interceptor-ref name="params"/>
> >                 <interceptor-ref name="servletConfig"/>
> >                 <interceptor-ref name="prepare" />
> >                 <interceptor-ref name="i18n"/>
> >                 <interceptor-ref name="chain"/>
> >                 <interceptor-ref name="modelDriven"/>
> >                 <interceptor-ref name="fileUpload"/>
> >                 <interceptor-ref name="checkbox"/>
> >                 <interceptor-ref name="staticParams"/>
> >                 <interceptor-ref name="params"/>
> >                 <interceptor-ref name="conversionError"/>
> >                 <interceptor-ref name="validation">
> >                     <param name="excludeMethods">input,back,cancel</param>
> >                 </interceptor-ref>
> >                 <interceptor-ref name="workflow">
> >                     <param name="excludeMethods">input,back,cancel</param>
> >                 </interceptor-ref>
> >             </interceptor-stack>
> >         </interceptors>
> >
> >         <default-interceptor-ref name="myInterceptors"/>
> >         <global-results>
> >             <result name="error">/error.jsp</result>
> >         </global-results>
> >
> >         <action name="productDetail" class="productDetailAction"
> > method="input">
> >             <result name="success"
> > type="redirect-action">productList</result>
> >             <result
> > name="input">/WEB-INF/secure/formulary/productDetail.jsp</result>
> >             <result name="success-subcategory" type="redirect-action">
> >                 <param name="actionName">subcategoryDetail</param>
> >                 <param name="parse">true</param>
> >                 <param name="id">${subcategoryId}</param>
> >             </result>
> >         </action>
> >
> >             </package>
> > </struts>
> > --
> > Jim Kiley
> > Technical Consultant | Summa
> > [p] 412.258.3346 [m] 412.445.1729
> > http://www.summa-tech.com
> 
> 
> 
> 


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


Re: Struts 2 Annotation Validation Problem

Posted by Jim Kiley <jh...@summa-tech.com>.
I solved this problem and I figure that nabble might want to record the end
reason for the bug.

Another method entirely, elsewhere on ProductDetailAction, had a
@Transactional annotation.  It didn't need one -- I was using injected
transaction management and the OpenEntityManagerInViewFilter.  Why the error
message below was generated, instead of "hey dummy, don't use @Transactional
in this context," is beyond me, but at least it's fixed.

jk

On Wed, Apr 30, 2008 at 3:47 PM, Jim Kiley <jh...@summa-tech.com> wrote:

> Hi folks,
>
> I've run into a problem with Struts 2 validation annotations.
>
> In short -- I have a VisitorFieldValidator on an action POJO named
> ProductDetailAction.  I have RequiredFieldValidator and
> RequiredStringValidator on one field within the "visited" object.
>
> Now -- ProductDetailAction did not (originally) inherit from
> ActionSupport.  I could see validation errors cropping up in my log, but my
> save() method was still executing, because , as I understand it, without
> ActionSupport (or ValidationAware) there was no way for Struts to redirect
> my action back to my input() method when it found a validation error.
>
> If I change the hierarchy so that ProductDetailAction DOES inherit,
> indirectly, from ActionSupport, I can't even get to my input() method -- my
> productDetail JSP doesn't render. Instead I get the following exception:
>
> java.lang.IllegalArgumentException: The input() is not defined in action
> class $Proxy99
>     at
> com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:412)
>     at
> com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
>     at
> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
>     at
> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
> (...)
>
> I get the same exception if I simply implement ValidationAware in the same
> way that ActionSupport does.
>
> I'm including relevant snippets of ProductDetailAction, Product, and
> struts.xml below.  Does anyone have any insight as to why this might be
> happening?  I'm stumped, and so are my coworkers.  Thanks.
>
> Jim
>
> -----
> ProductDetailAction.java
> -----
> @Validation
> public class ProductDetailAction extends FormularyDetailAction { // note:
> FormularyDetailAction extends ActionSupport
> // snippery
>
>     @Override
>     @SkipValidation
>     public String input() throws Exception {
>         if(id==null || id < 1) {
>             this.product = new Product();
>         } else {
>             this.product = formularyBso.fetchProduct(this.id);
>         }
>         return Action.INPUT;
>     }
>
>     @VisitorFieldValidator(message="")
>     public Product getProduct() {
>         return product;
>     }
> // snippery
> }
> -----
> Product.java
> -----
> @Entity
> @Table(name="myrespironics.p_product_versions")
> @Validation
> public class Product extends FormularyProduct {
>     //snip
> @RequiredFieldValidator(message="Please enter a value.")
>     @RequiredStringValidator(message="Please enter a value.")
>     public String getName() {
>         return name;
>     }
> //snip
> }
> -----
> struts.xml
> -----
> <struts>
>     <package name="user" extends="struts-default">
>           <interceptors>
>             <interceptor-stack name="myInterceptors">
>                 <interceptor-ref name="exception"/>
>                 <interceptor-ref name="alias"/>
>                 <interceptor-ref name="params"/>
>                 <interceptor-ref name="servletConfig"/>
>                 <interceptor-ref name="prepare" />
>                 <interceptor-ref name="i18n"/>
>                 <interceptor-ref name="chain"/>
>                 <interceptor-ref name="modelDriven"/>
>                 <interceptor-ref name="fileUpload"/>
>                 <interceptor-ref name="checkbox"/>
>                 <interceptor-ref name="staticParams"/>
>                 <interceptor-ref name="params"/>
>                 <interceptor-ref name="conversionError"/>
>                 <interceptor-ref name="validation">
>                     <param name="excludeMethods">input,back,cancel</param>
>                 </interceptor-ref>
>                 <interceptor-ref name="workflow">
>                     <param name="excludeMethods">input,back,cancel</param>
>                 </interceptor-ref>
>             </interceptor-stack>
>         </interceptors>
>
>         <default-interceptor-ref name="myInterceptors"/>
>         <global-results>
>             <result name="error">/error.jsp</result>
>         </global-results>
>
>         <action name="productDetail" class="productDetailAction"
> method="input">
>             <result name="success"
> type="redirect-action">productList</result>
>             <result
> name="input">/WEB-INF/secure/formulary/productDetail.jsp</result>
>             <result name="success-subcategory" type="redirect-action">
>                 <param name="actionName">subcategoryDetail</param>
>                 <param name="parse">true</param>
>                 <param name="id">${subcategoryId}</param>
>             </result>
>         </action>
>
>             </package>
> </struts>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com




-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com