简体   繁体   中英

Struts2 xml validation form fields not highlighting

I am able to validate form fields using XML validation and able to display error messages on screen. But form fields like text fields, radio buttons, check boxes are not highlighting in red after validation error messages throws on screen. Should I use CSS to show up fields turn to red...?

When using theme="simple" on a form you lose the default fielderror , so you need to create one manually:

<s:fielderror>
    <s:param>nameOfTheFormField1</s:param>
    <s:param>nameOfTheFormField2</s:param>
    <!-- More -->
</s:fielderror>

You can check the documentation for configure it the way you want.

And here you have a complete example.

Struts2表单标签(例如<s:textfield><s:radio>等)具有cssErrorStylecssErrorClass属性。

<s:textfield key="fieldName" cssErrorStyle="background-color: red;" />

Insert the tag <s:head /> in your JSP page(which you are validating) it will work fine for you. The errors will be highlighted with red and bold.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM