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]

Reply via email to