Issue Details (XML | Word | Printable)

Key: WW-649
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: tm_jee
Reporter: Matt Raible
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
WebWork

Field errors should be displayed in the order they're in the POJO

Created: 28/Sep/04 06:15 PM   Updated: 02/Mar/06 11:23 AM
Component/s: Views
Affects Version/s: 2.1.1
Fix Version/s: 2.2.2

File Attachments: 1. XML File User-validation.xml (3 kB)



 Description  « Hide
It would be nice if the fieldErrors were displayed in the order that they appear after validating the form. The following (at the top of my form) renders a pretty random order (not at all in-line with the field or POJO properties order).

     <ww:iterator value="fieldErrors">
         <ww:iterator value="value">
           <img src="<c:url value="/images/iconWarning.gif"/>"
               alt="<fmt:message key="icon.warning"/>" class="icon" />
            <ww:property/><br />
         </ww:iterator>
     </ww:iterator>



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Mathias Bogaert added a comment - 19/Oct/04 07:36 AM
This is very simple; in ValidationAwareSupport, change the internalGetFieldErrors method to initialize the fieldErrors with a LinkedHashMap instead of the current HashMap. I don't have developer access to XWork module, so I can't change this right now.

Mathias Bogaert added a comment - 26/Nov/04 07:30 AM
Fixed in XWork 1.0.4.

Matt Raible added a comment - 24/Feb/06 01:27 AM
This issue still happens in xwork-1.1.1.jar. I'll attach my User-validation.xml so you can see the order of validation rules. The error messages are stacked in a somewhat random order:

E-Mail is a required field.
Username is a required field.
Password Hint is a required field.
First Name is a required field.
State is a required field.
Zip is a required field.
City is a required field.
Country is a required field.
Password is a required field.
Website is a required field.
Last Name is a required field.
Confirm Password is a required field.

Matt Raible added a comment - 24/Feb/06 01:28 AM
validation file that has rules in preferred order of error output

tm_jee added a comment - 28/Feb/06 10:54 AM
just skimming through the code, and notice somthing that might be causing this bug.

At ValidationAwareSupport.java

   private Map internalGetFieldErrors() {
        if (fieldErrors == null) {
            fieldErrors = new HashMap();
        }

        return fieldErrors;
    }

should instead be

  private Map internalGetFieldErrors() {
        if (fieldErrors == null) {
            fieldErrors = new LinkedHashMap();
        }

        return fieldErrors;
    }

LinkedHashMap or some map which honours sequence in added order should be used. I will work on some testcase within the next few days (hopefully) to verify it.

tm_jee added a comment - 02/Mar/06 11:23 AM
changes are :

src/test/com/opensymphony/xwork/ValidationOrderAction-validation.xml
src/test/com/opensymphony/xwork/ValidationOrderAction.java
src/java/com/opensymphony/xwork/ValidationAwareSupport.java
src/test/com/opensymphony/xwork/validator/DefaultActionValidatorManagerTest.java