Ads

US Oil and Gas Drilling Data

Wednesday, June 08, 2005

Struts Error Messages

Ok. So after looking all over God's green earth to find documentation on how to print out an icon next to the field that fails validation, I've finally come up with something. This seems so common it should be flashing in red from the Struts home page. None the less, I will post my solution here so that others can avoid the anguish I went through trying to find this documented. I'm sure there are other ways, if so please share so we can all learn, but this is what I came up with. I added a new "td" to the table and gave it a width="17", and either print out the icon or a non-breaking space, this keeps the fields from moving around when errors are found.

I'll cut right to the chase assuming you have properly configured the struts validator and ApplicationResource.properties file and have the errors printing where ever you put your "html:errors" tag.

explanation: this tag is pretty straight forward. The property corresponds to the name of the property which you want to print out your error indicator. The content can be whatever you want to print out when that field fails validation. We choose to print out an icon.



Hopefully this will help many people out there who are having the same issue, and based on my Google searches, there were many looking for this and no one seemed to know how to do it.

No comments: