Eric Wilson
Eric Wilson

Reputation: 59355

How to print a specific actionerror message with Struts2 validation?

When using Struts2 validation, when you put the <s:actionerror> tag in your JSP, the default behavior is to display all the action errors at that point in the page.

Is there a way to display only specific error messages at that point? For example, in the case of fielderror one only needs to add the fieldName attribute. Is there an attribute of actionerror that accomplishes similar behavior?

Upvotes: 2

Views: 3145

Answers (1)

р&#252;ффп
р&#252;ффп

Reputation: 5448

For field specific error the function is : hasFieldErrors()

You can use it like this:

<s:if test="hasFieldErrors()">
    <div class="fieldErrors">
        <!-- iterate through the fields errors, customize what you need -->
        <s:iterator value="fieldErrors">
            <s:property value="key"/>:
            <s:iterator value="value">
                <s:property/>
            </s:iterator>
        </s:iterator>
    </div>
</s:if>

References:

Interesting reading:

Upvotes: 2

Related Questions