|
From: Eric B. <eri...@ho...> - 2002-01-17 15:54:37
|
Hi Anthony,
Actually FormProc works by mapping distinct name to the XML file.
To avoid to create as much of entries in this XML file as we have in
a web form, we use the "element" as a kind of validation TYPE and
we do the mapping for the validation.
Used in DBForms it can looks like :
<db:textField fieldName="phoneWork" fieldValidator="phoneCanada"/>
<db:textField fieldName="phoneHome" fieldValidator="phoneCanada"/>
<db:textField fieldName="phoneCell" fieldValidator="phoneCanada"/>
<db:textField fieldName="fax" fieldValidator="phoneCanada"/>
...
and because DBForms generate a fuzzy name for each textfield in the form
(looks like NAME="f_0_0@root_4")
we can't use it anayway.
<element name="phoneCanada">
<validator type="group">
<validator type="expression">
<pattern>^[0-9]{10}$</pattern>
<error lang="en">The % is invalid.</error>
<error lang="fr">Le % est invalide.</error>
<error lang="sp">El % es inválido.</error>
</validator>
<validator type="expression">
<pattern>^(204|250|289|306|403|416|418|450|506|514|519|604|613|647|705|709|778|780|807|819|867|902|905)</pattern>
<error lang="en">The % has a invalid Canada area code.</error>
<error lang="fr">Le % a un indicatif régional Canadien
invalide.</error>
<error lang="sp">El % tiene inválido Canadiense un código de
área.</error>
</validator>
</validator>
</element>
Here, when we will retrieve the error message we will replace the "%" by the
appropriate expression
(ex: "The home phone has a invalid Canada area code") in our DBForms
Interceptor.
For this reason, we can't validate the ArrayList correctly because we don't
know
which one is in error with the isValid("phoneCanada") method.
ArrayList formDataList = new ArrayList();
formDataList.add(new FormData("phoneCanada", request("phoneWork")));
formDataList.add(new FormData("phoneCanada", request("phoneHome")));
formDataList.add(new FormData("phoneCanada", request("phoneCell")));
formDataList.add(new FormData("phoneCanada", request("fax")));
I can perhaps suggest one of two solutions for this problem.
(1) Better one :
Adding a new property to the FormData class (ex: String context)
Like this, when we will retrieve the Enumeration of the errors by
the getErrorElements() of ValidationResultMap class, we will enable
to retrieve the context of which "phoneCanada" validation are in error...
ArrayList formDataList = new ArrayList();
formDataList.add(new FormData("phoneCanada", request("phoneWork"),
"phoneWork"));
formDataList.add(new FormData("phoneCanada", request("phoneHome"),
"phoneHome"));
formDataList.add(new FormData("phoneCanada", request("phoneCell"),
"phoneCell"));
formDataList.add(new FormData("phoneCanada", request("fax"), "fax"));
(2) Allowing the "validate" method in Form class as "public" to do the
validation
one by one ... But first one is far better.
"public ValidationResult validate(FormData formData) throws Exception{"
// phoneWork
ValidationResult results = form.validate(new FormData("phoneCanada",
request("phoneWork"));
if(result.isValid() {}
// phoneHome
ValidationResult results = form.validate(new FormData("phoneCanada",
request("phoneHome"));
if(result.isValid() {}
...
Finnally, I did not have enough time to look the code for retrieving error
message for
a specific validator... But is it possible to retrieve error message for a
specific
language?
...
<validator type="expression">
<pattern>^[0-9]{10}$</pattern>
<error lang="en">The % is invalid.</error>
<error lang="fr">Le % est invalide.</error>
<error lang="sp">El % es inválido.</error>
</validator>
...
Thanks again.
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
|