When an input field fails validation, an error message can be displayed. That's good, but I would also like to change the appearance of the field that failed validation. Specifically, I would like to change the color of the border on the problem field(s) to red.
Unfortunately, I can't find any easy way to do this. I'm thinking of something (very roughly) like this...
...which I know wouldn't even come close to working, because "employee.validation" won't magically return "inputError" simply because "hours" failed the validator.
I have a feeling that the only way to do this is to write my own validator (which I haven't learned how to do yet) and have it set/clear a property of the bean (which sounds to me like a no-no).
Is there a standard/better way to change the appearance of a form field when it fails validation?
Well, that looks like it's exactly what I want -- except I can't get it to work.
Trying that, I get this error: "javax.faces.el.PropertyNotFoundException: Error getting property 'valid' from bean of type java.lang.Integer"
I noticed that in your example, you used "binding=" rather than "value=". Is that perhaps the source of my problem? I've never used "binding=" before, so I tried just changing "value=" to "binding=" and got an incomprehensible error message that simply confirmed that there's more to it than that.
Yes, you will need to use binding because the valid() method exists in the component itself.
In your backing bean...
Then in your backing bean
Try that and see if it works out for you. Remember that you aren't getting and setting the value of a String/Integer/etc for maxDays anymore. You are binding it to an HtmlInputText component and will need to call the .value() method to actually get the input from the text field.