From: Anthony E. <me...@an...> - 2002-06-02 18:32:16
|
> -----Original Message----- > From: for...@li...=20 > [mailto:for...@li...] On=20 > Behalf Of Ken Keller > Sent: Sunday, June 02, 2002 12:22 PM > To: Anthony Eden; FormProc Developer List > Subject: [FormProc-developer] I haven't tested FormProcService yet >=20 >=20 > First let me say that at ign.com we're been using our own=20 > validation framework for over a year. Now I'm surveying what=20 > others have done. Your framework looks very well done. Glad you like it. It is good mostly because of the input I have received from others using it. >=20 > * * * >=20 > If you leave the age field blank, you get: >=20 > java.lang.NullPointerException > at org.formproc.example.IsIntRule.validate(Unknown Source) > at=20 > org.formproc.validation.RuleValidator.validate(Unknown Source) > at=20 > org.formproc.validation.ValidatorGroup.validate(Unknown Source) > at org.formproc.Form.validate(Unknown Source) > at org.formproc.Form.process(Unknown Source) > at org.formproc.Form.process(Unknown Source) > at org.formproc.Form.process(Unknown Source) > at org.formproc.servlet.HttpForm.process(Unknown Source) Which FormProc version are you using? >=20 > <shared-validator name=3D"age"> > <validator type=3D"group"> > <validator type=3D"rule"> > <rule>org.formproc.example.IsIntRule</rule> > <error>Valid number required</error> > <error lang=3D"fr">L'=E2ge valide a exig=E9.</error> > </validator> > <validator type=3D"expression"> > <pattern>[1-9][0-9]*</pattern> > <error>Age must be 1 or greater</error> > </validator> > </validator> > </shared-validator> >=20 > Should the expression validator be listed before the IsIntRule? The IsIntRule isn't necessary, per se. I only included it in this context as a way to demonstrate how group validators work. > Since the age field isn't marked required, why do the=20 > validators get applied when the field is blank? It is required, even if the message doesn't say so. Validators are always applied on a field if the validator exists. If there is no validator for a field then a PassValidator will be used which just passes the value through as valid. >=20 > * * * >=20 > In the example, you decided to hold the form's state in a=20 > User in the session. This doesn't seem correct to me. It=20 > seems preferable to redisplay the invalid form w/ the invalid=20 > strings. After all, you're validating from the HttpRequest=20 > via HttpForm. So would the code be something like this? >=20 > Age: > <% if (! elementResults.isValid("age")) { >% > <input type=3D"text" name=3D"age" value=3D"<%=3D=20 > req.getParameter("age") %>"> <font color=3D"#ff0000"> <% else {=20 > %> <input type=3D"text" name=3D"age" value=3D"<%=3D user.getAge()=20 > %>"> <font> <% } %> <%=3D form.getMessage("age", locale) %> </font> You could design it that way. The only reason I hold it in the object in the session is because in my systems objects in the session are only saved when an explicit save() method (or something similar) is called. Thus the in-memory state is only for temporary storage. You could also store the results in a HashMap. Check out the org.formproc.store.MapStorer class. Eventually I will include another example which will use that as an example. You can also create a custom Storer to function however it makes sense for you. Another Storer which I am working on will store the data in an XML document. > * * * >=20 > formManager.configure(form); >=20 > To avoid repeated parsing of the XML, should the formManager=20 > be instantiated once per app? Yes. > * * * >=20 > > BTW: Have you tried the FormProcService which is a TurbineService=20 > > implementation yet? I haven't tested it yet so I would be=20 > interested=20 > > if anyone who does use Turbine on a regular basis would=20 > take a look at=20 > > it. It is in the CVS in the turbine-service module. >=20 > Turbine 2.1? Did you program this service? Is there any documentation? >=20 > Thx. -Ken I believe I wrote it against 2.2b2 API. It is actually in the FormProc CVS - there is no affiliation with Turbine. It is just something which I threw together quickly so it may not even work. The only documentation is in the code (JavaDoc). I would definitely classify it as "experimental". :-) Sincerely, Anthony Eden |