my dog learned polymorphism*
The moose likes JSF and the fly likes Get field validation status from ui component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Get field validation status from ui component" Watch "Get field validation status from ui component" New topic
Author

Get field validation status from ui component

Denis Oleshkevich
Greenhorn

Joined: Jul 19, 2012
Posts: 3
Hello.
I want set a special error class to div block into my custom component for JSF. Need set errorClass to "error" if this field failed the validation.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

Welcome to the JavaRanch, Denis!

JSF View Definition Language is not a programming language, it's a View templating language. What this means is that a View Definition is not a linear sequence of instructions, it is a 2-dimensional template of the desired display. Therefore linear constructs such as JSTL "set" elements cannot be expected to work properly.

The setting of HTML div-level attributes based on the status of JSF elements within them is not common practice and I cannot think of an easy way to do it. In any event, you don't seem to have attached any validation constraints to the inputText control, so I wouldn't expect to even see any JSF validation errors.

In cases where validation is in effect, such as the "required="true"" constraint, the usual custom when you want to flag the offending control is to bind an h:message tag to the control.


Customer surveys are for companies who didn't pay proper attention to begin with.
Denis Oleshkevich
Greenhorn

Joined: Jul 19, 2012
Posts: 3
Thanks for answer, Tim.

For example, if needed make input's label red, this no problem with class in wrapping div. Anyway may use jQuery for copy class, but it is not beauty way.

I already use h:message for display error text in this component and I really happy that this works=)

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

jQuery can probably do it. if you attach an "oncomplete" script to your submit button that invokes a jQuery script that checks for the presence of text in the "h:message", then that script could adjust the div's class properties.
 
GeeCON Prague 2014
 
subject: Get field validation status from ui component