Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
Hi, Nikolaos I don't think the choice of JS framework could affect validation in any way. After all you do use ajax, don't you? :) Here's how we solved it in one of our projects: 1. On client side we add an event listener to each form field (we listen for onChange event). 2. This event listener does a plain vanilla ajax request. Something like: /my/action/bean?fieldName=User+ValueajaxValidate=atrue In our action bean we have fields with some validation rules and (optionally) custom methods assigned. If we leave it as is it won't handle our request correctly because some other fields might be required. That's why .. 3. Our action bean implements ValidationErrorHandler [1] interface to hijack the default validation handling mechanism. 4. By the time handleValidationErrors method is called all validation rules are already applied and ValidationErrors array is already filled in. 5. Inside this handleValidationErrors we check for ajaxValidate parameter in request and if it's present we filter out validation errors corresponding to filedName field. 6. If no errors are found we return a JSON {status: 'ok'}. Otherwise we return JSON with validation errors. 7. On a client side aour Ajax callback function expects a JSON response data. If JSON has any errors we show them to user. It's not really hard to implement ajax validation this way and it's completely library-agnostic. In our project we use jQuery so I don't show the code to you to avoid confusion. But if you follow the guidelines that's going to be easy. Note that we still required to have a ajaxValidate handler defined in our action bean. It's going to be invoked when the last field in a form is being validated and is going to pass validation. This is because in this case ValidationErrors array is empty and handleValidationErrors isn't called. If this method isn't defined Stripes will use a default handler - and it might be not something you intend to. Cheers, Andrey [1] http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/validation/ValidationErrorHandler.html On Mon, 15 Nov 2010 20:05:09 +0200, Nikolaos Giannopoulos nikol...@brightminds.org wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}tag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages exist in resource bundles on the Stripes server side yet the messages need to be accessible to provide the correct message to the user... Ajax is one possibility... using a generic set of translated messages is another... but all don't appear optimal. Much Appreciated. --Nikolaos -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev ___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users -- Using Opera's revolutionary email client: http://www.opera.com/mail/ -- Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today http://p.sf.net/sfu/msIE9-sfdev2dev ___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users
Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
Andrey, Clearly the choice of JS framework is not the issue here. However, what I was looking for was a MooTools version of the jQuery script that Aaron Porter wrote that leverages the field-metadata tag and that is why I mentioned MooTools here. Your suggestion however is very interesting and sounds very simple to implement and does solve the localization of error messages. However, I am concerned thought that doing an Ajax call per each field change will amount to a lot of extra server requests and may be a performance clog on a high traffic site. Did you ever consider limiting to 1 Ajax request on hitting form submit... basically a pre-validation to actual form submission? Thoughts??? --Nikolaos Andrey Listochkin wrote: Hi, Nikolaos I don't think the choice of JS framework could affect validation in any way. After all you do use ajax, don't you? :) Here's how we solved it in one of our projects: 1. On client side we add an event listener to each form field (we listen for onChange event). 2. This event listener does a plain vanilla ajax request. Something like: /my/action/bean?fieldName=User+ValueajaxValidate=atrue In our action bean we have fields with some validation rules and (optionally) custom methods assigned. If we leave it as is it won't handle our request correctly because some other fields might be required. That's why .. 3. Our action bean implements ValidationErrorHandler [1] interface to hijack the default validation handling mechanism. 4. By the time handleValidationErrors method is called all validation rules are already applied and ValidationErrors array is already filled in. 5. Inside this handleValidationErrors we check for ajaxValidate parameter in request and if it's present we filter out validation errors corresponding to filedName field. 6. If no errors are found we return a JSON {status: 'ok'}. Otherwise we return JSON with validation errors. 7. On a client side aour Ajax callback function expects a JSON response data. If JSON has any errors we show them to user. It's not really hard to implement ajax validation this way and it's completely library-agnostic. In our project we use jQuery so I don't show the code to you to avoid confusion. But if you follow the guidelines that's going to be easy. Note that we still required to have a ajaxValidate handler defined in our action bean. It's going to be invoked when the last field in a form is being validated and is going to pass validation. This is because in this case ValidationErrors array is empty and handleValidationErrors isn't called. If this method isn't defined Stripes will use a default handler - and it might be not something you intend to. Cheers, Andrey [1] http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/validation/ValidationErrorHandler.html On Mon, 15 Nov 2010 20:05:09 +0200, Nikolaos Giannopoulos nikol...@brightminds.org wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}tag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages exist in resource bundles on the Stripes server side yet the messages need to be accessible to provide the correct message to the user... Ajax is one possibility... using a generic set of translated messages is another... but all don't appear optimal. Much Appreciated. --Nikolaos -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev ___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users -- Nikolaos Giannopoulos Director of Information Technology BrightMinds Software Inc. e. nikol...@brightminds.org w. www.brightminds.org t. 1.613.822.1700 c. 1.613.797.0036 f. 1.613.822.1915
Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
You can return a JSP file in response to your AJAX request (return new ForwardResolution(/ajax-response.jsp)). Making it super easy to include your errors and messages (s:errors/ and s:messages/). Not the best traffic saver though. But at least it allows you to update small portions of your site. Cheers, -- Samuel Santos http://www.samaxes.com/ On Tue, Nov 16, 2010 at 3:03 PM, Nikolaos Giannopoulos nikol...@brightminds.org wrote: Andrey, Clearly the choice of JS framework is not the issue here. However, what I was looking for was a MooTools version of the jQuery script that Aaron Porter wrote that leverages the field-metadata tag and that is why I mentioned MooTools here. Your suggestion however is very interesting and sounds very simple to implement and does solve the localization of error messages. However, I am concerned thought that doing an Ajax call per each field change will amount to a lot of extra server requests and may be a performance clog on a high traffic site. Did you ever consider limiting to 1 Ajax request on hitting form submit... basically a pre-validation to actual form submission? Thoughts??? --Nikolaos Andrey Listochkin wrote: Hi, Nikolaos I don't think the choice of JS framework could affect validation in any way. After all you do use ajax, don't you? :) Here's how we solved it in one of our projects: 1. On client side we add an event listener to each form field (we listen for onChange event). 2. This event listener does a plain vanilla ajax request. Something like: /my/action/bean?fieldName=User+ValueajaxValidate=atrue In our action bean we have fields with some validation rules and (optionally) custom methods assigned. If we leave it as is it won't handle our request correctly because some other fields might be required. That's why .. 3. Our action bean implements ValidationErrorHandler [1] interface to hijack the default validation handling mechanism. 4. By the time handleValidationErrors method is called all validation rules are already applied and ValidationErrors array is already filled in. 5. Inside this handleValidationErrors we check for ajaxValidate parameter in request and if it's present we filter out validation errors corresponding to filedName field. 6. If no errors are found we return a JSON {status: 'ok'}. Otherwise we return JSON with validation errors. 7. On a client side aour Ajax callback function expects a JSON response data. If JSON has any errors we show them to user. It's not really hard to implement ajax validation this way and it's completely library-agnostic. In our project we use jQuery so I don't show the code to you to avoid confusion. But if you follow the guidelines that's going to be easy. Note that we still required to have a ajaxValidate handler defined in our action bean. It's going to be invoked when the last field in a form is being validated and is going to pass validation. This is because in this case ValidationErrors array is empty and handleValidationErrors isn't called. If this method isn't defined Stripes will use a default handler - and it might be not something you intend to. Cheers, Andrey [1] http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/validation/ValidationErrorHandler.html On Mon, 15 Nov 2010 20:05:09 +0200, Nikolaos Giannopoulos nikol...@brightminds.org wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}taghttp://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe%7B%7Bfieldmetadata%7D%7Dtag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages exist in resource bundles on the Stripes server side yet the messages need to be accessible to provide the correct message to the user... Ajax is one possibility... using a generic set of translated messages is another... but all don't appear optimal. Much Appreciated. --Nikolaos -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying
Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
Pakin, Welcome to this mailing list. It's great that you are interested in collaborating. I totally agree that Stripes needs work in the Validation area on the server side... and any thoughts would be welcome. However, this specific thread is about how to hook in client side validation so as to pre-validate form input so as to improve the user experience, reduce server load, etc... . I don't believe JSR-303 has anything to offer here? Does it? ASIDE: Feel free to start a new thread on JSR-303 Validation. In fact, if you look in the archives someone provided some code (although I don't recall the details, how thorough it was, etc...). Again, I don't get me wrong but I think another thread might be very worthwhile... . --Nikolaos Pakin wrote: Hi all, I am new in town and I would like to collaborate... I think that validation-wise, it would be more interesting trying to tackle the issue of: how to integrate Stripes server and client validation with JSR-303 Frameworks like Spring MVC 3 or Loom already have it and I think it is indeed a competitive advantage over Stripes. I think Stripes validation should adopt JSR-303 because it is standard and most of the constraints to be validated come from the database and currently with stripes you have take care about those explicitly. You can find more information about what Spring MVC does here: http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html Cheers, Angel. Nikolaos Giannopoulos wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}tag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages exist in resource bundles on the Stripes server side yet the messages need to be accessible to provide the correct message to the user... Ajax is one possibility... using a generic set of translated messages is another... but all don't appear optimal. Much Appreciated. --Nikolaos -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev ___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users -- Nikolaos Giannopoulos Director of Information Technology BrightMinds Software Inc. e. nikol...@brightminds.org w. www.brightminds.org t. 1.613.822.1700 c. 1.613.797.0036 f. 1.613.822.1915 -- Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today http://p.sf.net/sfu/msIE9-sfdev2dev___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users
Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
That's OK, although I want to clarify that they are related matters as what I was suggesting has to be also reflected in client validation. Pretty much the use case would be the following: The framework detects if there is any JSR-303 provider in the classpath, if so it uses all your JPA annotated pojos that are binded to any form, so the stripes taglibs would generate client validations at jsp rendering time. Somehow this client validation should be able to be cross-javascript-framework sort to speak. Although I reckon that jQuery is the de facto standard here. Once the form is submitted the system detects if the form backing bean is a persisted object with JPA annotation and perform the validations among other validations you may have. This way you don't need to repeat your DB backend related constraints using the custom Stripes validation annotations. IMHO it would be a very agile and convenient feature. Cheers mate, Angel. Nikolaos Giannopoulos wrote: Pakin, Welcome to this mailing list. It's great that you are interested in collaborating. I totally agree that Stripes needs work in the Validation area on the server side... and any thoughts would be welcome. However, this specific thread is about how to hook in client side validation so as to pre-validate form input so as to improve the user experience, reduce server load, etc... . I don't believe JSR-303 has anything to offer here? Does it? ASIDE: Feel free to start a new thread on JSR-303 Validation. In fact, if you look in the archives someone provided some code (although I don't recall the details, how thorough it was, etc...). Again, I don't get me wrong but I think another thread might be very worthwhile... . --Nikolaos Pakin wrote: Hi all, I am new in town and I would like to collaborate... I think that validation-wise, it would be more interesting trying to tackle the issue of: how to integrate Stripes server and client validation with JSR-303 Frameworks like Spring MVC 3 or Loom already have it and I think it is indeed a competitive advantage over Stripes. I think Stripes validation should adopt JSR-303 because it is standard and most of the constraints to be validated come from the database and currently with stripes you have take care about those explicitly. You can find more information about what Spring MVC does here: http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html Cheers, Angel. Nikolaos Giannopoulos wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}tag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages exist in resource bundles on the Stripes server side yet the messages need to be accessible to provide the correct message to the user... Ajax is one possibility... using a generic set of translated messages is another... but all don't appear optimal. Much Appreciated. --Nikolaos -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev ___ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users -- Nikolaos Giannopoulos Director of Information Technology BrightMinds Software Inc. e. nikol...@brightminds.org w. www.brightminds.org t. 1.613.822.1700 c. 1.613.797.0036 f. 1.613.822.1915 -- Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today
Re: [Stripes-users] Form Validation: Stripes and MooTools (field-metadata Tag)
Pakin, Comments in-line... . Pakin wrote: That's OK, although I want to clarify that they are related matters as what I was suggesting has to be also reflected in client validation. Okay... you mentioned JSR-303 but didn't mention client side validation so that was the disconnect. Pretty much the use case would be the following: The framework detects if there is any JSR-303 provider in the classpath, if so it uses all your JPA annotated pojos that are binded to any form, I am right there with you. And this is where Stripes validation doesn't go far enough. so the stripes taglibs would generate client validations at jsp rendering time. Though Stripes validation does attempt to help in this regard with the field-metadata that can be injected into a form Somehow this client validation should be able to be cross-javascript-framework sort to speak. Stipes-stuff has jQuery files that integrate Stripes field-metadata. Although I reckon that jQuery is the de facto standard here. Why do people feel inclined or the need to call JQuery a de facto standard. It's a framework that is popular. There are many other JS frameworks that are as good and for the OO purists perhaps even better. It's like saying Spring MVC is the de facto standard of web frameworks. In any event, my personal take is that MooTools is like Stripes... maybe not the most popular... but the best thought out. Once the form is submitted the system detects if the form backing bean is a persisted object with JPA annotation and perform the validations among other validations you may have. This way you don't need to repeat your DB backend related constraints using the custom Stripes validation annotations. IMHO it would be a very agile and convenient feature. It would be very convenient and barring the JSR-303 aspect Stripes does that today... at least w/ the help of Aaron's Stripes Stuff. I was hoping that someone had done something similar w/ MooTools. And I agree that JSR-303 is the way to go and that the entire validation process from server, through client, through annotations (JPA, what not,...) needs to be thought out and built into Stripes in a proper and robust manner. So are you volunteering... like I said there was a post on this mailing list w/ some JSR-303 code... ;-) Cheers, --Nikolaos Cheers mate, Angel. Nikolaos Giannopoulos wrote: Pakin, Welcome to this mailing list. It's great that you are interested in collaborating. I totally agree that Stripes needs work in the Validation area on the server side... and any thoughts would be welcome. However, this specific thread is about how to hook in client side validation so as to pre-validate form input so as to improve the user experience, reduce server load, etc... . I don't believe JSR-303 has anything to offer here? Does it? ASIDE: Feel free to start a new thread on JSR-303 Validation. In fact, if you look in the archives someone provided some code (although I don't recall the details, how thorough it was, etc...). Again, I don't get me wrong but I think another thread might be very worthwhile... . --Nikolaos Pakin wrote: Hi all, I am new in town and I would like to collaborate... I think that validation-wise, it would be more interesting trying to tackle the issue of: how to integrate Stripes server and client validation with JSR-303 Frameworks like Spring MVC 3 or Loom already have it and I think it is indeed a competitive advantage over Stripes. I think Stripes validation should adopt JSR-303 because it is standard and most of the constraints to be validated come from the database and currently with stripes you have take care about those explicitly. You can find more information about what Spring MVC does here: http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html Cheers, Angel. Nikolaos Giannopoulos wrote: Hi, I noticed the following page which shows how to integrate Stripes w/ client side validation via JQuery: http://www.stripesframework.org/display/stripes/Validation+Reference#ValidationReference-Usingthe{{fieldmetadata}}tag Has anyone done anything similar w/ MooTools? If so, was it a rewrite of Aaron's code or did it hook into MooTools Form Validation? And if so - anything shared would be appreciated. We are debating whether to do this now (though are short on time - what else is new) but anything that accelerates that could help us and in turn we would post it back to the community. I also realize the effort isn't huge but JQuery notation is new to me and doing this right w/ MooTools and classes will result in a pretty extensive re-write I'm afraid. Lastly, this is probably a stretch but did anyone solve the localization issue in all of this i.e. localized error messages