• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get field validation status from ui component

 
Denis Oleshkevich
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Denis Oleshkevich
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic