You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pavel Sapozhnikov <pa...@gmail.com> on 2007/08/29 17:08:05 UTC

Validation chaining in struts2

Hey guys. Could somebody provide some input on validation chaining in s2.
Here's what I need to do. So there has to be a base validation which would
validate variable x and variable y then every other class has its own
validation for example Login class would validate if username and password
exist but the prerequisite is that base validation should pass. How do I do
that in struts2. Any input would be appreciated. Thanks.

-- 
Pavel Sapozhnikov
xFact, Inc
pavel@xfact.com

Re: Validation chaining in struts2

Posted by Pavel Sapozhnikov <pa...@gmail.com>.
Hey Joseph sorry I think I need something exactly like this:

https://issues.apache.org/struts/browse/STR-443

On 8/29/07, Pavel Sapozhnikov <pa...@gmail.com> wrote:
>
> Hey Joseph. I think thats something similar to what I am asking but I am
> not even quiet sure. I was also wondering what if I have a method in class
> and I have ClassName-methodName-validation.xml file which would validate
> those base things so then in struts.xml I can do
> <type="redirect-action">toThatMethod  and when it redirects it will
> automatically do the validation from that xml. So would that serve my
> purpose?
>
> On 8/29/07, j alex <st...@gmail.com> wrote:
> >
> > Sounds very similar to the problem i had but no straightforward solution
> > yet
> > ; i've put this for enhancement on JIRA -
> >
> > https://issues.apache.org/struts/browse/WW-2113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41901
> >
> > Can you please check if this is what you need as well?
> >
> > -Joseph
> >
> >
> >
> > On 8/29/07, Pavel Sapozhnikov <pa...@gmail.com> wrote:
> > >
> > > Hey guys. Could somebody provide some input on validation chaining in
> > s2.
> > > Here's what I need to do. So there has to be a base validation which
> > would
> > > validate variable x and variable y then every other class has its own
> > > validation for example Login class would validate if username and
> > password
> > > exist but the prerequisite is that base validation should pass. How do
> > I
> > > do
> > > that in struts2. Any input would be appreciated. Thanks.
> > >
> > > --
> > > Pavel Sapozhnikov
> > > xFact, Inc
> > > pavel@xfact.com
> > >
> >
>
>
>
> --
> Pavel Sapozhnikov
> xFact, Inc
> pavel@xfact.com
>



-- 
Pavel Sapozhnikov
xFact, Inc
pavel@xfact.com

Re: Validation chaining in struts2

Posted by Pavel Sapozhnikov <pa...@gmail.com>.
Hey Joseph. I think thats something similar to what I am asking but I am not
even quiet sure. I was also wondering what if I have a method in class and I
have ClassName-methodName-validation.xml file which would validate those
base things so then in struts.xml I can do
<type="redirect-action">toThatMethod  and when it redirects it will
automatically do the validation from that xml. So would that serve my
purpose?

On 8/29/07, j alex <st...@gmail.com> wrote:
>
> Sounds very similar to the problem i had but no straightforward solution
> yet
> ; i've put this for enhancement on JIRA -
>
> https://issues.apache.org/struts/browse/WW-2113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41901
>
> Can you please check if this is what you need as well?
>
> -Joseph
>
>
>
> On 8/29/07, Pavel Sapozhnikov <pa...@gmail.com> wrote:
> >
> > Hey guys. Could somebody provide some input on validation chaining in
> s2.
> > Here's what I need to do. So there has to be a base validation which
> would
> > validate variable x and variable y then every other class has its own
> > validation for example Login class would validate if username and
> password
> > exist but the prerequisite is that base validation should pass. How do I
> > do
> > that in struts2. Any input would be appreciated. Thanks.
> >
> > --
> > Pavel Sapozhnikov
> > xFact, Inc
> > pavel@xfact.com
> >
>



-- 
Pavel Sapozhnikov
xFact, Inc
pavel@xfact.com

Re: Validation chaining in struts2

Posted by j alex <st...@gmail.com>.
Sounds very similar to the problem i had but no straightforward solution yet
; i've put this for enhancement on JIRA -
https://issues.apache.org/struts/browse/WW-2113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41901

Can you please check if this is what you need as well?

-Joseph



On 8/29/07, Pavel Sapozhnikov <pa...@gmail.com> wrote:
>
> Hey guys. Could somebody provide some input on validation chaining in s2.
> Here's what I need to do. So there has to be a base validation which would
> validate variable x and variable y then every other class has its own
> validation for example Login class would validate if username and password
> exist but the prerequisite is that base validation should pass. How do I
> do
> that in struts2. Any input would be appreciated. Thanks.
>
> --
> Pavel Sapozhnikov
> xFact, Inc
> pavel@xfact.com
>

Re: Validation chaining in struts2

Posted by Ted Husted <hu...@apache.org>.
On 8/30/07, j alex <st...@gmail.com> wrote:
> Regarding field validations, can you provide any reason why the validwhen
> validator is not provided in Struts 2? . I think this is a step backwards
> from Struts 1 where we could easily manage conditional validation (validate
> fieldb only if fielda & fieldc meet some condition)

It's important to remember that Struts 2 is not a direct port of
Struts 1. The codebases developed in parallel over a number of years.
I expect it's simply that no one has written a validwhen validator for
XWork yet. The Commons Validator didn't have one for a long time too.


> Also, the validators in Struts 1 returned true/false for success/failure,
> and we had the option of adding messages or not ; but in Struts 2 the only
> way to tell a validation failed is by the presence of errors on the field.
>
> Both of these limitations (if you will) make conditional validation (without
> error message for the condition itself) almost impossible.
>
> Hope i'm not missing anything here. Please let us know your thoughts

I never used the Common Validator that way myself. People often make
complex validations in the Action method and then let the framework
handle the simple cases.

Of course, there's much to be desired in either validation framework,
which is why Jason has been trying to get a JSR going.

 * http://jcp.org/en/jsr/detail?id=303

Though, I'm not sure if much headway is being made.

Personally, I'd like to see a fresh approach to validation that also
included type conversion and text formatting as part of the workflow,
and that did not throw away internally-created objects, just so that
we can convert them a second time. I'd also like to see an API that we
could implement in JavaScript, as well as Java and C#.  (Or maybe a
JavaScript API that we could use via Rhino or JScript.)

Now see what happens when you ask for my thoughts!

-Ted.

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


Re: Validation chaining in struts2

Posted by j alex <st...@gmail.com>.
Ted,

Regarding field validations, can you provide any reason why the validwhen
validator is not provided in Struts 2? . I think this is a step backwards
from Struts 1 where we could easily manage conditional validation (validate
fieldb only if fielda & fieldc meet some condition)

Also, the validators in Struts 1 returned true/false for success/failure,
and we had the option of adding messages or not ; but in Struts 2 the only
way to tell a validation failed is by the presence of errors on the field.

Both of these limitations (if you will) make conditional validation (without
error message for the condition itself) almost impossible.

Hope i'm not missing anything here. Please let us know your thoughts

Thanks,
Joseph



On 8/30/07, Ted Husted <husted@apache.org > wrote:
>
> Struts 2 uses a hierarchical approach to validation which could be
> used to support a multi-page workflow. (Struts 1 simulates a hierarchy
> by using the page property on the ActionForm.) The validation follows
> the Java class, not the action mapping. If class2 extends class1, then
> when class2 is validated, the validations for class1 also fire.
>
> If you like to collect all the methods for a workflow into a single
> class, then, in practice, class2 might be an empty class that only
> exists to appease the XWork Validation system.
>
> HTH, Ted
> <http://www.husted.com/ted/blog/>
>
>
> On 8/29/07, Pavel Sapozhnikov <pavel.sapozhnikov@gmail.com > wrote:
> > Hey guys. Could somebody provide some input on validation chaining in
> s2.
> > Here's what I need to do. So there has to be a base validation which
> would
> > validate variable x and variable y then every other class has its own
> > validation for example Login class would validate if username and
> password
> > exist but the prerequisite is that base validation should pass. How do I
> do
> > that in struts2. Any input would be appreciated. Thanks.
> >
> > --
> > Pavel Sapozhnikov
> > xFact, Inc
> > pavel@xfact.com
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Validation chaining in struts2

Posted by Ted Husted <hu...@apache.org>.
Struts 2 uses a hierarchical approach to validation which could be
used to support a multi-page workflow. (Struts 1 simulates a hierarchy
by using the page property on the ActionForm.) The validation follows
the Java class, not the action mapping. If class2 extends class1, then
when class2 is validated, the validations for class1 also fire.

If you like to collect all the methods for a workflow into a single
class, then, in practice, class2 might be an empty class that only
exists to appease the XWork Validation system.

HTH, Ted
<http://www.husted.com/ted/blog/>


On 8/29/07, Pavel Sapozhnikov <pa...@gmail.com> wrote:
> Hey guys. Could somebody provide some input on validation chaining in s2.
> Here's what I need to do. So there has to be a base validation which would
> validate variable x and variable y then every other class has its own
> validation for example Login class would validate if username and password
> exist but the prerequisite is that base validation should pass. How do I do
> that in struts2. Any input would be appreciated. Thanks.
>
> --
> Pavel Sapozhnikov
> xFact, Inc
> pavel@xfact.com
>

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