You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shoaib Gauhar <sa...@yahoo.com> on 2007/11/22 05:57:21 UTC

Struts 2 validation off at page load

Hello,

I am new to struts 2 validation architecture. I am facing a problem which might be very simple. I am adding all of my validation rules in the actionclass-validation.xml. It works fine. But what happens is that when the JSP page opens for the first time, it validates the fields and shows all the error messages (ideally it should not validate the fields, because the first time the page loads, all the fields are empty). So, what i want is not to validate when the page opens for the first time and after that it should.

I hope you guys understand my query.

Shoaib Ahmad


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


Re: Struts 2 validation off at page load

Posted by Dave Newton <ne...@yahoo.com>.
An action's validation will fire unless an action
method specifically excluded by the validation
interceptor, the validation file is for a specific
action class/method alias, or a couple other things
not relevant in your case.

There are a few ways around this, the simplest being
to run the "input" method on first hitting the page;
this can be done in a few ways, like dynamic method
invocation, wildcard action mapping, etc.

<action name="foo_*" class="full.action.class"
method="{1}">
    ....

(or method="do{1}" if you want to exclude other public
methods from the possibility of being executed; there
was a somewhat lengthy thread about this earlier this
week/last week.)

Hitting /foo_input.action will run the "input" method,
which is excluded from validation by default.

Another way would be to have two action mappings for
the same class, more or less like this:

<action name="foo" class="full.action.class"
method="input">
    ....

<action name="bar" class="full.action.class"
method="execute">
    ...

className-bar-validation.xml

The S2 documentation wiki covers these options (and
probably a few more) and there are a few WebWork
validation articles out there as well, I believe
they're linked to on the wiki.

d.

--- Shoaib Gauhar <sa...@yahoo.com> wrote:

> Hello,
> 
> I am new to struts 2 validation architecture. I am
> facing a problem which might be very simple. I am
> adding all of my validation rules in the
> actionclass-validation.xml. It works fine. But what
> happens is that when the JSP page opens for the
> first time, it validates the fields and shows all
> the error messages (ideally it should not validate
> the fields, because the first time the page loads,
> all the fields are empty). So, what i want is not to
> validate when the page opens for the first time and
> after that it should.
> 
> I hope you guys understand my query.
> 
> Shoaib Ahmad
> 
> 
>      
>
____________________________________________________________________________________
> Never miss a thing.  Make Yahoo your home page. 
> http://www.yahoo.com/r/hs
> 
>
---------------------------------------------------------------------
> 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