I'm having a conversation with David Winterfeldt regarding how the
validator works, specifically with Struts. He suggested I raise the
question here for more input.
If I have three fields, defined:
<field property="lastName" depends="required">
<arg0 key="subscriberForm.lastName.label"/>
</field>
<field property="dateOfBirth" depends="required,date">
<arg0 key="subscriberForm.dateOfBirth.label"/>
</field>
<field property="dateOfDeath" depends="date">
<arg0 key="subscriberForm.dateOfDeath.label"/>
</field>
The way the validator *should* behave, in my opinion:
field value result
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth <empty> Error
dateOfDeath <empty> No Error
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth <empty> Error
dateOfDeath Garbage Error
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth Garbage Error
dateOfDeath Garbage Error
--------------------------------------------------------------------------
Unfortunately, the way it works right now is that:
1) date implies required in validator-rules.xml, which means that all
dates are required. You can only make a date (or float, or any other
type-validated field) optional by removing the "required" from
validator-rules.xml
2) If you remove the required dependency from validator-rules, it still
doesn't work right, because if you put a non-date in dateOfBirth and
leave lastName empty, only lastName will generate an error, because
the way Validator is written right now, if any dependency flags an error
(even in another field), it stops validation beyond that dependency in
all fields.
So the matrix looks like this at the moment:
field value result
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth <empty> Error
dateOfDeath <empty> Error (because date implies required)
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth <empty> Error
dateOfDeath Garbage No Error (because required failing on
other fields stops
date validation here)
--------------------------------------------------------------------------
lastName <empty> Error
dateOfBirth Garbage No Error (because required failing on
other fields stops
date validation here)
dateOfDeath Garbage No Error (because required failing on
other fields stops
date validation here)
--------------------------------------------------------------------------
In my opinion, I couldn't deploy a commercial site right now using the
code as is, because it doesn't handle validations in the way a user
would expect.
I have a patch for Validator I've submitted that refactors validate()
and makes it work right for the cases above. Am I the only
one who thinks it's important to make this work the way most
developers would expect it to?
James
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>