• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ganesh Podaralla
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic