When validation fails for a component, I am trying to do is the following:
- Change the border of inputs that has not failed validation to green
- Change the border of inputs that has failed validation to red
- On the top of the page, render a list that has internationalized label/message pairs
- Show only error messages
What I have so far:
I use Bean validation:
@Size(min = 5, max = 20)
I manage the colouring with JS/JQuery with the following:
- I render a hidden field with validation status:
styleClass="hidden #{facesContext.validationFailed?'failed-validation':'success-validation'}"
- On the components to be validated I set the individual validation status:
#{component.valid?'input-valid-tobe':'input-error'}"
- On my Ajax action I register a
onevent="xxx"
function that replaces the CSS with the correct valid ones.i.e. I only want to highlight the validated ones if validation has failed:
function xxx(data){ if(data.status == "success"){ if ($('.failed-validation')[0]){ $('.input-valid-tobe').addClass('input-valid'); } } }
Now to the problem, rendering the messages: I would like to render a list that shows a label and a message for the component.
Messages:
I suppose I could use bean validation I18N as describe here for the messages:
How does it work with bean validation messages and i18n in JSF2? http://jcp.org/aboutJava/communityprocess/edr/jsr303/index.html
..But, I was hoping that maybe there is something new in JSF 2.2! Is there?
Labels:
Shouldn't <h:messages/>
render the labels for the input fields? (It doesn't for some reason)
Filtering:
Is there a way to filter the messages by severity
?
(other than creating a custom bean of using CSS to hide messages that I don't want to show)