• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get field validation status from ui component

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic