• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make required and requiredMessage attributes visible to the client browser

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using required and requiredMessage attributes in JSF for server side validation. I am planning to create a JavaScript and do client side validations using these two (required and requiredMessage) attributes. But, when I saw the HTML Source code at the client browser, these two attributes are not present. Is there anyway I can make the JSF attributes to be visible to the client browser? I am trying to make this one work generically rather than implementing a solution for every UIComponent. Please help me to find the solution.

Thanks,
Ganesh
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like all JSP tags, the JSF tags are compiled on the server. In the case of JSF, the actual client-side results of that compilation are created by a renderer. There's a standard HTML renderer for the core tags.

There is no "required" attribute defined in the official HTML spec (RFC), and the JSF HTML renderers don't produce illegal HTML (such as HTML containing non-standard elements). To get around that, you'd have to replace the standard HTML renderer with one of your own construction. And debug it. And maintain it. And keep it updated as new versions of JSF came out.

There are better ways. Ideally, you should find a JSF extension tagset that supports client-side validations directly. Tags like that would automatically generate the requisite javascript, customize it according to the quirks of the user's browser, and (ideally) even fall back to server-side validation for users who disable javascript.

I don't know if there are any such tagsets, but if there aren't, there should be. If not, you could always create your own by subclassing the standard tag classes. That's essentially the same thing as replacing the standard renderer, but it's a more complete and more durable way of doing it.
reply
    Bookmark Topic Watch Topic
  • New Topic