You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Lentz <Er...@sherwin.com> on 2011/07/18 14:03:11 UTC

Conditional fire on validation()

I'm using the wildcard method in my configuration

    <action name="foo-*" class="FooAction" method="{1}">
      <result name="success">pages/foo.jsp</result> ...

and I want validation to fire only upon the call to the method that 
performs the save/update. No problem with the XML file as the name takes 
care of that (e.g., assuming "save" is the method name: 
FooAction-foo-save-validation.xml).

What about when I use the validate() method? Is there a 
standard/convention for that? I did the following, but I'm wondering if 
that is the "best" way.

        String invokingMethod = 
ActionContext.getContext().getActionInvocation().getProxy().getMethod();
        if (invokingMethod.equals("save")) {
          // Do validation
        }

That solution adds more framework into my action class which I'm not wild 
about, but I already have interfaces and I'm extending ActionSupport, so 
adding one more thing... okay I guess?

I realize I could validate inside my "save" method, but again, I'm 
wondering what the /best/ approach is (i.e., standard/convention).

- Eric

RE: Conditional fire on validation()

Posted by Baubak Gandomi <b....@castsoftware.com>.
Hello Eric,

Another way of doing this would be using aliases. In other words the
validation.xml file follows the action name not the class. 

If you send save action "foo-save" and method "save"

<action name="foo-*" class="FooAction" method="{1}">
      <result name="success">pages/foo.jsp</result>


You create one declarative validation file per call

So you add a validation file per possible action ....

foo-save.xml

foo-delete.xml

etc....

why not check :

http://struts.apache.org/2.x/docs/validation.html#Validation-HowValidato
rsofanActionareFound

http://struts.apache.org/2.x/docs/validation.html#Validation-DefiningVal
idationRules




-----Original Message-----
From: Eric Lentz [mailto:Eric.Lentz@sherwin.com] 
Sent: lundi 18 juillet 2011 14:16
To: Struts Users Mailing List
Subject: Re: Conditional fire on validation()

> I'm not sure it's exactly what you're looking for, but IIRC there
should 
be
> a convention for the validate method, such that you can call, for 
example, a
> method validateSave, expecting that it's fired contextually with the 
save
> action
> 
> Maurizio Cucchiara

Oh yeah! I remember coming across that now. Post 40 with all these 
frameworks I have stuffed in my head... thanks for the reminder.

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


Re: Conditional fire on validation()

Posted by Eric Lentz <Er...@sherwin.com>.
> I'm not sure it's exactly what you're looking for, but IIRC there should 
be
> a convention for the validate method, such that you can call, for 
example, a
> method validateSave, expecting that it's fired contextually with the 
save
> action
> 
> Maurizio Cucchiara

Oh yeah! I remember coming across that now. Post 40 with all these 
frameworks I have stuffed in my head... thanks for the reminder.

Re: Conditional fire on validation()

Posted by Maurizio Cucchiara <ma...@gmail.com>.
I'm not sure it's exactly what you're looking for, but IIRC there should be
a convention for the validate method, such that you can call, for example, a
method validateSave, expecting that it's fired contextually with the save
action

Maurizio Cucchiara

Il giorno 18/lug/2011 14.03, "Eric Lentz" <Er...@sherwin.com> ha
scritto:
I'm using the wildcard method in my configuration

   <action name="foo-*" class="FooAction" method="{1}">
     <result name="success">pages/foo.jsp</result> ...

and I want validation to fire only upon the call to the method that
performs the save/update. No problem with the XML file as the name takes
care of that (e.g., assuming "save" is the method name:
FooAction-foo-save-validation.xml).

What about when I use the validate() method? Is there a
standard/convention for that? I did the following, but I'm wondering if
that is the "best" way.

       String invokingMethod =
ActionContext.getContext().getActionInvocation().getProxy().getMethod();
       if (invokingMethod.equals("save")) {
         // Do validation
       }

That solution adds more framework into my action class which I'm not wild
about, but I already have interfaces and I'm extending ActionSupport, so
adding one more thing... okay I guess?

I realize I could validate inside my "save" method, but again, I'm
wondering what the /best/ approach is (i.e., standard/convention).

- Eric