2

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?

Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
  • But, by definition, actionErrors are "global", while fieldErrors are associated to fields. (You can think of actionErrors as Collection, and fieldErrors as Map> ) And recall that the (programmatic) way of generating actionErrors is Action.addActionError(String) So, I don't imagine what you mean by "display only specific error messages". Specific how? – leonbloy Apr 05 '10 at 20:02

1 Answers1

2

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:

рüффп
  • 5,172
  • 34
  • 67
  • 113
  • I'll upvote your contribution. I'll not accept, because I'm not in a position to determine if this provides what I need. The project is finished, and I work for a different company. – Eric Wilson Jul 23 '10 at 16:46