You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by lebenski <be...@gamesys.co.uk> on 2008/04/30 18:11:25 UTC

Re: T5: New Validators and server side validation

+1

I would find this functionality extremely useful.  Server-side validation
onBlur has so many applications.  At the moment the solution I have come up
with is:

1) Use the T5Components OnEvent annotation, and attach a blur event to the
field.
2) Do my server side validation (in this case checking if a username exists
in the database) in my page class onBlur method.
3) Callback to a javascript function with a result (true or false, i.e.
exists or doesnt exist).
4a) If exists call another function that emulates the tapestry
addDecorations function to apply Validation pop up etc to the field.
4b) If doesnt exist, remove decorations if they are present.

Its a shame that this isnt properly integrated into the Tapestry validation
framework, and I don't get all the benefits like preventing form submission
if the form has recorded errors, out of the box.

I would approve of the addition of this functionality Mr Lewis-Ship!

Cheers,
Ben.


LakshithaS wrote:
> 
> I think there is a better option than just using regex for email
> validation, that is use apache common validator to do the same thing in an
> easy manner.
> like
> 
> EmailValidator.getInstance().isValid(emailAddress);
> 
> 
> 
> Howard Lewis Ship wrote:
>> 
>> I agree:
>> - onblur vs. onform submit
>> - option to validate via server-round trip (especially for onblur)
>> 
>> On 5/17/07, kranga <kr...@k2d2.org> wrote:
>>>
>>> We just introduced client side validation for Tapestry fields using an
>>> ajax
>>> call back to the server side (with Tapestry 3). So you only write Java
>>> code
>>> for the validation and the same code gets called from the client side.
>>> All
>>> parameters for controlling your validation are automatically sent back
>>> as
>>> part of the ajax call and you can define when the check is triggered
>>> (e.g.
>>> onBlur) and which one of the "error marker" components tied to the input
>>> field will show the errors. Makes the code very clean and the front-end
>>> experience is slick (e.g. registration page has the same validator to
>>> check
>>> if username is taken and this is fired from the client and from the
>>> server!). I'd suggest T5 move to such a design.
>>>
>>> ----- Original Message -----
>>> From: "Bill Holloway" <bi...@gmail.com>
>>> To: "Tapestry users" <us...@tapestry.apache.org>
>>> Sent: Wednesday, May 16, 2007 2:27 PM
>>> Subject: Re: T5: New Validators and server side validation
>>>
>>>
>>> > That's got it, Ben.  Thanks.  Wish I knew more about javascript
>>> > prototyping.  Too much technology to stay familiar with.
>>> >
>>> > Bill
>>> >
>>> > On 5/16/07, Ben Sommerville <be...@bulletproof.com.au> wrote:
>>> >> Bill,
>>> >>
>>> >> This
>>> >> > pageRenderSupport.addScript(
>>> >> >                 "Tapestry.Field.email('%s', %s);",
>>> >> >                 field.getClientId(),
>>> >> >                 quote(buildMessage(formatter, field)));
>>> >>
>>> >> does not construct a function validating emails.  What it is doing is
>>> >> inserting
>>> >> a function call to register a particular field for validation.
>>> >>
>>> >> On the page sent to the client you would get something like
>>> >>
>>> >> <script language="javascript" type="text/javascript">
>>> >>         <!--
>>> >>                 Tapestry.registerForm('MyFormId');
>>> >>                 Tapestry.Field.email('MyFieldId','My message ')l
>>> >>        -->
>>> >> </script>
>>> >>
>>> >> That is the source of your error message, the Tapestry.Field.email
>>> >> function
>>> >> does not exist but you are trying to call it.
>>> >>
>>> >> What you need to do is define the email validation function yourself
>>> in
>>> a
>>> >> javascript file.  I would add it to a different namespace so that it
>>> is
>>> >> clear
>>> >> it is not a standard Tapestry function.
>>> >>
>>> >> e.g. in myproject-valdation.js
>>> >>
>>> >> var MyProject = {};
>>> >>
>>> >> MyProject.Field =  {
>>> >>
>>> >>     email: function(field, message) {
>>> >>         Tapestry.addValidator(field, false, function(value, event) {
>>> >>             if( XXXXX ) {
>>> >>                 event.recordError(message)
>>> >>             }
>>> >>         });
>>> >>     }
>>> >> }
>>> >>
>>> >> where XXXX is the javascript to test if "value" is a valid email
>>> address.
>>> >>
>>> >> Add a script include to your border/page (to load your validation
>>> >> function)
>>> >>         <script language="javascript" type="text/javascript"
>>> >> src="js/myproject-validation.js"></script>
>>> >>
>>> >> and change the render method to use MyProject.Field.email and you are
>>> >> good
>>> >> to go
>>> >>
>>> >> cheers.
>>> >> --
>>> >> Ben Sommerville
>>> >>
>>> >>
>>> >>
>>> >> > -----Original Message-----
>>> >> > From: Bill Holloway [mailto:bill.holloway@gmail.com]
>>> >> > Sent: Wednesday, 16 May 2007 4:33 PM
>>> >> > To: Tapestry users
>>> >> > Subject: Re: T5: New Validators and server side validation
>>> >> >
>>> >> > In implementing an e-mail validator myself, one thing I notice in
>>> all
>>> >> > this is a Javascript error that reads
>>> >> >
>>> >> > Error: Tapestry.Field.email is not a function...
>>> >> >
>>> >> > I did some digging and found in org/apache/tapestry/tapestry.js the
>>> >> > building up of the Tapestry object has in it a section involving
>>> >> > "Collection of field based functions related to validation."  In
>>> that
>>> >> > part of the object prototyping (I guess), each of the built-in
>>> >> > validation types (required, minlength, maxlength, min, and max) has
>>> a
>>> >> > function assigned that, essentially, duplicates the functionality
>>> of
>>> >> > the Java-based validators.  All that prototyping must be for the
>>> >> > client-side functionality.
>>> >> >
>>> >> > So I'm wondering why my AppModule-provided EmailValidator class'
>>> >> > render() method isn't contributing the script.  Its code is
>>> >> >
>>> >> > pageRenderSupport.addScript(
>>> >> >                 "Tapestry.Field.email('%s', %s);",
>>> >> >                 field.getClientId(),
>>> >> >                 quote(buildMessage(formatter, field)));
>>> >> >
>>> >> > Since I implementing something for render(), I would think that at
>>> >> > least some kind of function for Tapestry.Field.email would show up
>>> >> > (even if it has the wrong number of fields, etc), knocking out the
>>> >> > "...is not a function" error.
>>> >> >
>>> >> > Bill
>>> >> >
>>> >>
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > "The future is here.  It's just not evenly distributed yet."
>>> >
>>> >     -- Traditional
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> > For additional commands, e-mail: users-help@tapestry.apache.org
>>> >
>>> >
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> 
>> 
>> -- 
>> Howard M. Lewis Ship
>> TWD Consulting, Inc.
>> Independent J2EE / Open-Source Java Consultant
>> Creator and PMC Chair, Apache Tapestry
>> Creator, Apache HiveMind
>> 
>> Professional Tapestry training, mentoring, support
>> and project work.  http://howardlewisship.com
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-New-Validators-and-server-side-validation-tp10616222p16986289.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org