From: Anthony E. <me...@an...> - 2002-01-21 22:57:46
|
Eric, I am not sure how I want to proceed with this as your situation seems somewhat unique. Do you think other users will use FormProc in a similar manner and thus require some sort of second name which is separate from the actual form field name. I suppose I need to look at DBForms to understand what it is doing exactly (I can't get to the dbforms.org site right now though). Regarding error messages for a particular language: this is currently part of the FormElement class (i.e. error messages are for a complete form element, not on a per-validator basis) but not part of the ValidatorResult. I will look into this as soon as possible as it seems reasonable to want to know which validator caused the error. -Anthony > -----Original Message----- > From: for...@li... > [mailto:for...@li...]On Behalf Of Eric > Beaumier > Sent: Thursday, January 17, 2002 10:54 AM > To: for...@li... > Subject: [FormProc-developer] Validation by type > > > > 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 > > > _______________________________________________ > FormProc-developer mailing list > For...@li... > https://lists.sourceforge.net/lists/listinfo/formproc-developer > |