Re: How to have logical 'OR' between two validator rules ?

2005-07-28 Thread Marc Demlenne
Thanks for the reply, 

This only allows you to compare fields, not to enter a regular
expression mask in the test var. So uit's not enought, except if I'm
totally wrong.
I don't need to have an 'OR' between fields, but between validator
results. That's the problem.
In fact, OR between validwhen and mask should be ok. 
The only solution I'fe found until now is to write a new validator for me. 



On 27/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> Yes, much clearer now.  If you're using Struts 1.2.x, There is a
> "validwhen" clause that may help you--look at the test example just
> below it:
> 
> http://struts.apache.org/userGuide/dev_validator.html#validwhen
> 
> Glen
> 
> 
> Marc Demlenne escribió:
> > Yes, sorry I made a mistake while explaining. I'll try to do it better now.
> >
> > Of course I need always to validate my form, you're right, sorry for
> > the confusion. But I need the form "to be valid" if either it is
> > validated threw the mask validator, OR if it is unchanged, even if in
> > this case it does not look like the mask wants any more.
> >
> > So I want a my field to be something like "^[0-9]{4}$". Ok, I use the
> > mask validator, and everything is fine.
> >
> > Now, if the value already stored in the DB isn't like this mask (there
> > are some good reasons to allow this), I want the user to be able to
> > modify everything in his form. If he doesn't change the value of this
> > field, everything should be correct. BUT if he decide to modify this
> > field, then he MUST enter a mask-valid field.
> >
> > To cope with this, I can use another field, the same, but hidden,
> > containing the original value, for example.  Then in my validation, I
> > would like,
> > - First to check if the given field is the same as the hidden one. In
> > this case it has not been modified, and I say validation returns true.
> > - Then, if those 2 fields are not the same, I check the real field
> > (the one enterered by user) against the mask threw the mask validator,
> > and I only accept all of this if this last validation returns true.
> >
> > Hope it's better explained ?
> >
> > Thanks Joe for this wonderful link. I have not yet verified
> > everything, but I'm affraid it won't be satisfying in my case ... I'm
> > still investigating ...
> >
> >
> >
> > On 27/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> >
> >>Marc Demlenne wrote:
> >>
> >>
> >>>Hi and thanks for the answer,
> >>>
> >>>In fact my problem could be explained the following way :
> >>>
> >>>Having two fields A and B, I need to validate A if
> >>>(A == mask) OR (A == B)
> >>
> >>Your way of stating the problem doesn't seem right and may be adding to
> >>the difficulties here--I would again think that you *always* need to
> >>validate A, it's just that validation passes 100% if the above two
> >>conditions fit, but passes/fails (depending on the results of more
> >>complex logic) if the above isn't correct.
> >>
> >>I.e., instead of saying, "If a ZIP code is provided, I need to validate
> >>that it is five digits long", why not:  "I need to validate that the ZIP
> >>code is either empty, or if not 5 digits"?
> >>
> >>Again, I'm unsure here (sorry, still a newbie), but using the p. 38
> >>example below, my inclination is that you can always validate but just
> >>change the validation logic if the scenario above occurs, something like:
> >>
> >>(Pseudocode):
> >>
> >>validate() {
> >>if (A.equals(mask) || a.equals(B)) {
> >>   return null; // validate always "true"
> >>} else {
> >>   // do actual validation,
> >>   // return ActionErrors or "null" as appropriate
> >>}
> >>}
> >>
> >>I hope someone else can provide a better answer for you though--as I'm
> >>also quite curious here.
> >>
> >>Glen
> >>
> >>
> >>
> >>>I don't know if it is possible to include a field in a mask
> >>>expression. But in the other case, I need to have an alternative
> >>>between the two validators. Is thos possible with struts validator ?
> >>>
> >>>If this isn't possible, I'll need to create my own validator plugin
> >>>
> >>>But if someone has eny advice, it's welcomed !
> >>>
> >>>
> >>>On 26/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> >>>
> >>>
> I'm not exactly certain of your needs, but I think you can always
> activate validation but just change the validation code based on the
> value/state of other fields (such as the "original" one you mention).
> 
> Perhaps the Java code example on page 38 of
> http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for
> you--I am unsure.
> 
> Glen
> 
> >>
> >
> >
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
Marc Demlenne

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to have logical 'OR' between two validator rules ?

2005-07-27 Thread Glen Mazza
Yes, much clearer now.  If you're using Struts 1.2.x, There is a 
"validwhen" clause that may help you--look at the test example just 
below it:


http://struts.apache.org/userGuide/dev_validator.html#validwhen

Glen


Marc Demlenne escribió:
Yes, sorry I made a mistake while explaining. I'll try to do it better now. 


Of course I need always to validate my form, you're right, sorry for
the confusion. But I need the form "to be valid" if either it is
validated threw the mask validator, OR if it is unchanged, even if in
this case it does not look like the mask wants any more.

So I want a my field to be something like "^[0-9]{4}$". Ok, I use the
mask validator, and everything is fine.

Now, if the value already stored in the DB isn't like this mask (there
are some good reasons to allow this), I want the user to be able to
modify everything in his form. If he doesn't change the value of this
field, everything should be correct. BUT if he decide to modify this
field, then he MUST enter a mask-valid field.

To cope with this, I can use another field, the same, but hidden,
containing the original value, for example.  Then in my validation, I
would like,
- First to check if the given field is the same as the hidden one. In
this case it has not been modified, and I say validation returns true.
- Then, if those 2 fields are not the same, I check the real field
(the one enterered by user) against the mask threw the mask validator,
and I only accept all of this if this last validation returns true.

Hope it's better explained ? 


Thanks Joe for this wonderful link. I have not yet verified
everything, but I'm affraid it won't be satisfying in my case ... I'm
still investigating ...



On 27/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:


Marc Demlenne wrote:



Hi and thanks for the answer,

In fact my problem could be explained the following way :

Having two fields A and B, I need to validate A if
(A == mask) OR (A == B)


Your way of stating the problem doesn't seem right and may be adding to
the difficulties here--I would again think that you *always* need to
validate A, it's just that validation passes 100% if the above two
conditions fit, but passes/fails (depending on the results of more
complex logic) if the above isn't correct.

I.e., instead of saying, "If a ZIP code is provided, I need to validate
that it is five digits long", why not:  "I need to validate that the ZIP
code is either empty, or if not 5 digits"?

Again, I'm unsure here (sorry, still a newbie), but using the p. 38
example below, my inclination is that you can always validate but just
change the validation logic if the scenario above occurs, something like:

(Pseudocode):

validate() {
   if (A.equals(mask) || a.equals(B)) {
  return null; // validate always "true"
   } else {
  // do actual validation,
  // return ActionErrors or "null" as appropriate
   }
}

I hope someone else can provide a better answer for you though--as I'm
also quite curious here.

Glen




I don't know if it is possible to include a field in a mask
expression. But in the other case, I need to have an alternative
between the two validators. Is thos possible with struts validator ?

If this isn't possible, I'll need to create my own validator plugin

But if someone has eny advice, it's welcomed !


On 26/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:



I'm not exactly certain of your needs, but I think you can always
activate validation but just change the validation code based on the
value/state of other fields (such as the "original" one you mention).

Perhaps the Java code example on page 38 of
http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for
you--I am unsure.

Glen








-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to have logical 'OR' between two validator rules ?

2005-07-27 Thread Marc Demlenne
Yes, sorry I made a mistake while explaining. I'll try to do it better now. 

Of course I need always to validate my form, you're right, sorry for
the confusion. But I need the form "to be valid" if either it is
validated threw the mask validator, OR if it is unchanged, even if in
this case it does not look like the mask wants any more.

So I want a my field to be something like "^[0-9]{4}$". Ok, I use the
mask validator, and everything is fine.

Now, if the value already stored in the DB isn't like this mask (there
are some good reasons to allow this), I want the user to be able to
modify everything in his form. If he doesn't change the value of this
field, everything should be correct. BUT if he decide to modify this
field, then he MUST enter a mask-valid field.

To cope with this, I can use another field, the same, but hidden,
containing the original value, for example.  Then in my validation, I
would like,
- First to check if the given field is the same as the hidden one. In
this case it has not been modified, and I say validation returns true.
- Then, if those 2 fields are not the same, I check the real field
(the one enterered by user) against the mask threw the mask validator,
and I only accept all of this if this last validation returns true.

Hope it's better explained ? 

Thanks Joe for this wonderful link. I have not yet verified
everything, but I'm affraid it won't be satisfying in my case ... I'm
still investigating ...



On 27/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> Marc Demlenne wrote:
> 
> > Hi and thanks for the answer,
> >
> > In fact my problem could be explained the following way :
> >
> > Having two fields A and B, I need to validate A if
> > (A == mask) OR (A == B)
> 
> Your way of stating the problem doesn't seem right and may be adding to
> the difficulties here--I would again think that you *always* need to
> validate A, it's just that validation passes 100% if the above two
> conditions fit, but passes/fails (depending on the results of more
> complex logic) if the above isn't correct.
> 
> I.e., instead of saying, "If a ZIP code is provided, I need to validate
> that it is five digits long", why not:  "I need to validate that the ZIP
> code is either empty, or if not 5 digits"?
> 
> Again, I'm unsure here (sorry, still a newbie), but using the p. 38
> example below, my inclination is that you can always validate but just
> change the validation logic if the scenario above occurs, something like:
> 
> (Pseudocode):
> 
> validate() {
> if (A.equals(mask) || a.equals(B)) {
>return null; // validate always "true"
> } else {
>// do actual validation,
>// return ActionErrors or "null" as appropriate
> }
> }
> 
> I hope someone else can provide a better answer for you though--as I'm
> also quite curious here.
> 
> Glen
> 
> 
> >
> > I don't know if it is possible to include a field in a mask
> > expression. But in the other case, I need to have an alternative
> > between the two validators. Is thos possible with struts validator ?
> >
> > If this isn't possible, I'll need to create my own validator plugin
> >
> > But if someone has eny advice, it's welcomed !
> >
> >
> > On 26/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> >
> >>I'm not exactly certain of your needs, but I think you can always
> >>activate validation but just change the validation code based on the
> >>value/state of other fields (such as the "original" one you mention).
> >>
> >>Perhaps the Java code example on page 38 of
> >>http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for
> >>you--I am unsure.
> >>
> >>Glen
> >>
> 


-- 
Marc Demlenne

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to have logical 'OR' between two validator rules ?

2005-07-27 Thread Joe Germuska
There are two validators which come with Struts: "requiredif" and 
"validwhen"; "validwhen" is considered the logical successor to 
"requiredif", although I have never really been comfortable using it.


One of my colleagues has submitted an enhancement request which uses 
the JEXL expression evaluator to support extremely rich conditional 
validation, and we're using it pretty successfully here.  The one 
limitation is that, because of how the  tag works, 
sometimes you end up with invalid javascript if you use client side 
validation with the JEXL validator.  (Note that the JEXL validator 
itself doesn't do any client-side validation.)


Anyway, there have been some concerns expressed about adding the 
dependencies required by the JEXL validator directly to the Struts 
core, and now that this other issue with client-side javascript has 
come up, I'm not going to rush to commit the changes -- but the 
patches are in Bugzilla, and anyone willing to spend an hour or less 
could augment their own Struts project with the code and use the JEXL 
validator.


See http://issues.apache.org/bugzilla/show_bug.cgi?id=34849 for my 
colleague's solution.  I just also came across 
http://issues.apache.org/bugzilla/show_bug.cgi?id=22743, an older 
solution from Rick Hightower which is equivalent in intent and which 
also provides code for an alternative solution.  The ticket for the 
dynamic JS bug is 
http://issues.apache.org/bugzilla/show_bug.cgi?id=35806


Hope this helps.

Joe


At 3:09 PM +0200 7/27/05, Marc Demlenne wrote:

Hi and thanks for the answer,

In fact my problem could be explained the following way :

Having two fields A and B, I need to validate A if
(A == mask) OR (A == B)

I don't know if it is possible to include a field in a mask
expression. But in the other case, I need to have an alternative
between the two validators. Is thos possible with struts validator ?

If this isn't possible, I'll need to create my own validator plugin

But if someone has eny advice, it's welcomed !


On 26/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:

 I'm not exactly certain of your needs, but I think you can always
 activate validation but just change the validation code based on the
 value/state of other fields (such as the "original" one you mention).

 Perhaps the Java code example on page 38 of
 http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for
 you--I am unsure.

 Glen


 Marc Demlenne wrote:
 > Hi,
 >
 > I need to use a text box that must correspond to a regular expression,
 > so it can be validated by the "mask" validator.
 >
 > However, if and only if this value remains unchanged by customer, it
 > has not to be validated and can stay as is, even if it doesn't
 > correspond to the mask. This could be easily done by checking the
 > value against another field containing the original one with
 > "validwhen" validator for instance.
 >
 > However, I need to have my field validated even if only one of those
 > validators are OK, not both ones.
 >
 > How can I make this using validator plugin ?
 >
 > Thanks very much for any answer.
 >

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





--
Marc Demlenne

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to have logical 'OR' between two validator rules ?

2005-07-27 Thread Marc Demlenne
Hi and thanks for the answer, 

In fact my problem could be explained the following way : 

Having two fields A and B, I need to validate A if 
(A == mask) OR (A == B)

I don't know if it is possible to include a field in a mask
expression. But in the other case, I need to have an alternative
between the two validators. Is thos possible with struts validator ?

If this isn't possible, I'll need to create my own validator plugin

But if someone has eny advice, it's welcomed !


On 26/07/05, Glen Mazza <[EMAIL PROTECTED]> wrote:
> I'm not exactly certain of your needs, but I think you can always
> activate validation but just change the validation code based on the
> value/state of other fields (such as the "original" one you mention).
> 
> Perhaps the Java code example on page 38 of
> http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for
> you--I am unsure.
> 
> Glen
> 
> 
> Marc Demlenne wrote:
> > Hi,
> >
> > I need to use a text box that must correspond to a regular expression,
> > so it can be validated by the "mask" validator.
> >
> > However, if and only if this value remains unchanged by customer, it
> > has not to be validated and can stay as is, even if it doesn't
> > correspond to the mask. This could be easily done by checking the
> > value against another field containing the original one with
> > "validwhen" validator for instance.
> >
> > However, I need to have my field validated even if only one of those
> > validators are OK, not both ones.
> >
> > How can I make this using validator plugin ?
> >
> > Thanks very much for any answer.
> >
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
Marc Demlenne

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to have logical 'OR' between two validator rules ?

2005-07-26 Thread Glen Mazza
I'm not exactly certain of your needs, but I think you can always 
activate validation but just change the validation code based on the 
value/state of other fields (such as the "original" one you mention).


Perhaps the Java code example on page 38 of
http://www.objectsource.com/Struts_Survival_Guide.pdf can be of help for 
you--I am unsure.


Glen


Marc Demlenne wrote:
Hi, 


I need to use a text box that must correspond to a regular expression,
so it can be validated by the "mask" validator.

However, if and only if this value remains unchanged by customer, it
has not to be validated and can stay as is, even if it doesn't
correspond to the mask. This could be easily done by checking the
value against another field containing the original one with
"validwhen" validator for instance.

However, I need to have my field validated even if only one of those
validators are OK, not both ones.

How can I make this using validator plugin ? 

Thanks very much for any answer. 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to have logical 'OR' between two validator rules ?

2005-07-26 Thread Marc Demlenne
Hi, 

I need to use a text box that must correspond to a regular expression,
so it can be validated by the "mask" validator.

However, if and only if this value remains unchanged by customer, it
has not to be validated and can stay as is, even if it doesn't
correspond to the mask. This could be easily done by checking the
value against another field containing the original one with
"validwhen" validator for instance.

However, I need to have my field validated even if only one of those
validators are OK, not both ones.

How can I make this using validator plugin ? 

Thanks very much for any answer. 

-- 
Marc Demlenne

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]