Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Core JSF, Chapter 12: Client-side validation  RSS feed

Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an example given in the book on how to use jakarta commons validator for client-side validation. If you work with that example you will see that the resultant html page would have all those javascript validation functions, which are used in that page. Some of those function will never change page to page and would be present, as it is, in every page having that validator. Like validateRequired, validateInteger.

All those methods, which are there in validator-rules.xml, would be written in the page as it is. Therefore, the size of the page would definitely increase. So, what I wanna suggest is to make a js file and place all those methods in there. Make a link to that file in jsp page. And remove the the functions from validator-rules.xml, but don't remove the name because the name is needed for callback. Stop the code from rendering those methods in every page, in which the validator is used.

validator-rules.xml before removal

validator-rules.xml after removal

Comment the below code in your file, method writeValidationFunctions(ResponseWriter writer, FacesContext context). Commenting will prevent the code from rendering javascript functions in individual pages.

It would work like a charm.
[ October 05, 2005: Message edited by: Adeel Ansari ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!