File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make required and requiredMessage attributes visible to the client browser