Difference between addfielderror and addactionerror

Source: Internet
Author: User
Both addactionerror () and addfielderror () are methods in the com. opensymphony. xwork2.actionsupport class.



Addactionerror (stringAnerrormessage)

Add an action-level error message to the action

Anerrormessage: error message


The label for displaying the message is (for example, on the JSP page ):

<S: actionerror/>Display All action-level error messages. You can add CSS code.

Anerrormessage is stored in the list. You can check the source code.



Addfielderror (stringFieldname, stringErrormessage)

Add an error message to a field (attribute)

Fieldname: field (attribute) Name

Errormessage: error message

Errormessage is stored in a map <key, value> (the key stores fieldname, and the value stores errormessage ). You can check the source code.


The label for displaying the message is (for example, on the JSP page ):

<! -- Example 1 -->

<S: fielderror/> Display All error messages (Added using addfielderror)


<! -- Example 2 -->

<S: fielderror>

<S: param> field1 </S: param> displays the error message of the specified field1 field.

<S: param> field2 </S: param> displays error messages for the specified field2 field.

</S: fielderror>

<S: form...>... </S: Form>


Under the default topic, <s: Form/> displays the error message and automatically adds the table layout. (the error message is displayed on the top of the input text box)

Modify the topic: <s: Form theme = "simple"> the error message cannot be displayed, and the table layout cannot be automatically added.


The actionsupport class also has a public Boolean haserrors () method,In fact, his internal implementation is like this:

(Hasactionerrors () | hasfielderrors ())Check whether there are action-level error messages and fidld-level error messages.

If one is true, it will jump back to the input real graph and display the error message (if you write the corresponding label)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.