Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight fields which fail Struts2 validation?

I have a user who would like to have the fields which fail Struts2 validation highlighted.

I plan to set a flag for any field which fails in my validate() method and use that field to change the background of the field when my JSP page is loaded.

My question is how do I handle the fields which fail the validation in my Action-validation.xml file ? Do I need to do all of my validation in my validate() method ?

Also is there a way to highlight the fields which generate an

Invalid field value for field ...

error ?

Any help would be appreciated!

like image 582
ponder275 Avatar asked Dec 14 '25 20:12

ponder275


1 Answers

This feature is already built in Struts2, no need for custom flags or whatever. In Struts2 form tags there is cssErrorClass attribute which will set CSS class for field on error.

<style type="text/css">
    .errField {
        background-color: red;
    }
</style>

<s:textfield key="name" cssErrorClass="errField" />
like image 105
Aleksandr M Avatar answered Dec 17 '25 09:12

Aleksandr M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!