jQuery in Action, 3rd edition
The moose likes JSF and the fly likes How to make required and requiredMessage attributes visible to the client browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to make required and requiredMessage attributes visible to the client browser" Watch "How to make required and requiredMessage attributes visible to the client browser" New topic
Author

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

Ganesh Podaralla
Greenhorn

Joined: Feb 22, 2010
Posts: 23
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

Joined: Jun 25, 2001
Posts: 17039
    
  26

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.


An IDE is no substitute for an Intelligent Developer.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: How to make required and requiredMessage attributes visible to the client browser
 
It's not a secret anymore!