aspose file tools*
The moose likes JSF and the fly likes Changing appearance of form fields with validation errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Changing appearance of form fields with validation errors" Watch "Changing appearance of form fields with validation errors" New topic
Author

Changing appearance of form fields with validation errors

Wally Hartshorn
Ranch Hand

Joined: Jan 30, 2003
Posts: 77
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?


Wally Hartshorn
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Would something like this work for you?


GenRocket - Experts at Building Test Data
Wally Hartshorn
Ranch Hand

Joined: Jan 30, 2003
Posts: 77
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.

Any suggestions?

Thanks!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Changing appearance of form fields with validation errors