1. opensymphony
  2. xwork

Commits

tmjee  committed 7844026

Issue number: ww-649
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@851e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 57393f8
  • Branches master

Comments (0)

Files changed (4)

File src/java/com/opensymphony/xwork/ValidationAwareSupport.java

View file
  * errors and messages (defensive copy).
  *
  * @author Jason Carreira
+ * @author tm_jee
+ * @version $Date$ $Id$
  */
 public class ValidationAwareSupport implements ValidationAware, Serializable {
 
     }
 
     public synchronized Map getFieldErrors() {
-        return new HashMap(internalGetFieldErrors());
+        return new LinkedHashMap(internalGetFieldErrors());
     }
 
     public synchronized void addActionError(String anErrorMessage) {
 
     private Map internalGetFieldErrors() {
         if (fieldErrors == null) {
-            fieldErrors = new HashMap();
+            fieldErrors = new LinkedHashMap();
         }
 
         return fieldErrors;

File src/test/com/opensymphony/xwork/ValidationOrderAction-validation.xml

View file
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE validators PUBLIC 
+  		"-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
+  		"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+	<field name="username">
+		<field-validator type="requiredstring">
+			<message>username required</message>
+		</field-validator>
+	</field>
+
+	<field name="password">
+		<field-validator type="requiredstring">
+			<message>password required</message>
+		</field-validator>
+	</field>
+
+	<field name="confirmPassword">
+		<field-validator type="requiredstring">
+			<message>confirm password required</message>
+		</field-validator>
+		<field-validator type="fieldexpression">
+			<param name="expression">
+                (confirmPassword.equals(password))
+			</param>
+			<message>confirmed password must match password</message>
+		</field-validator>
+	</field>
+	
+	<field name="firstName">
+		<field-validator type="requiredstring">
+			<message>first name required</message>
+		</field-validator>
+	</field>
+	
+	<field name="lastName">
+		<field-validator type="requiredstring">
+			<message>last name required</message>
+		</field-validator>
+	</field>
+
+	<field name="city">
+		<field-validator type="requiredstring">
+			<message>city is required</message>
+		</field-validator>
+	</field>
+	
+	<field name="province">
+		<field-validator type="requiredstring">
+			<message>province is required</message>
+		</field-validator>
+	</field>
+	
+	<field name="country">
+		<field-validator type="requiredstring">
+			<message>country is required</message>
+		</field-validator>
+	</field>
+	
+	<field name="postalCode">
+		<field-validator type="requiredstring">
+			<message>postal code is required</message>
+		</field-validator>
+	</field>
+	
+	<field name="email">
+		<field-validator type="requiredstring">
+			<message>email is required</message>
+		</field-validator>
+		<field-validator type="email">
+			<message>email is invalid</message>
+		</field-validator>
+	</field>
+
+	<field name="website">
+		<field-validator type="requiredstring">
+			<message>website is required</message>
+		</field-validator>
+	</field>
+	
+	<field name="passwordHint">
+		<field-validator type="requiredstring">
+			<message>password hint is required</message>
+		</field-validator>
+	</field>
+</validators>
+

File src/test/com/opensymphony/xwork/ValidationOrderAction.java

View file
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork;
+
+/**
+ * A sample action to test validation order.
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class ValidationOrderAction extends ActionSupport {
+	
+	private String username;
+	private String password;
+	private String confirmPassword;
+	private String firstName;
+	private String lastName;
+	private String city;
+	private String province;
+	private String country;
+	private String postalCode;
+	private String email;
+	private String website;
+	private String passwordHint;
+	
+	
+	
+	public String execute() throws Exception {
+		return SUCCESS;
+	}
+
+
+
+	public String getCity() {
+		return city;
+	}
+
+
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+
+
+	public String getConfirmPassword() {
+		return confirmPassword;
+	}
+
+
+
+	public void setConfirmPassword(String confirmPassword) {
+		this.confirmPassword = confirmPassword;
+	}
+
+
+
+	public String getCountry() {
+		return country;
+	}
+
+
+
+	public void setCountry(String country) {
+		this.country = country;
+	}
+
+
+
+	public String getEmail() {
+		return email;
+	}
+
+
+
+	public void setEmail(String email) {
+		this.email = email;
+	}
+
+
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+
+
+	public String getLastName() {
+		return lastName;
+	}
+
+
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+
+
+
+	public String getPassword() {
+		return password;
+	}
+
+
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+
+
+	public String getPasswordHint() {
+		return passwordHint;
+	}
+
+
+
+	public void setPasswordHint(String passwordHint) {
+		this.passwordHint = passwordHint;
+	}
+
+
+
+	public String getPostalCode() {
+		return postalCode;
+	}
+
+
+
+	public void setPostalCode(String postalCode) {
+		this.postalCode = postalCode;
+	}
+
+
+
+	public String getProvince() {
+		return province;
+	}
+
+
+
+	public void setProvince(String province) {
+		this.province = province;
+	}
+
+
+
+	public String getUsername() {
+		return username;
+	}
+
+
+
+	public void setUsername(String username) {
+		this.username = username;
+	}
+
+
+
+	public String getWebsite() {
+		return website;
+	}
+
+
+
+	public void setWebsite(String website) {
+		this.website = website;
+	}
+}

File src/test/com/opensymphony/xwork/validator/DefaultActionValidatorManagerTest.java

View file
 
 import com.opensymphony.xwork.SimpleAction;
 import com.opensymphony.xwork.TestBean;
+import com.opensymphony.xwork.ValidationOrderAction;
 import com.opensymphony.xwork.XWorkTestCase;
 import com.opensymphony.xwork.test.DataAware2;
 import com.opensymphony.xwork.test.SimpleAction2;
 import com.opensymphony.xwork.test.User;
 import com.opensymphony.xwork.validator.validators.*;
 
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 
 /**
  * DefaultActionValidatorManagerTest
  *
  * @author Jason Carreira
- * @author tm_jee ( tm_jee (at) yahoo.co.uk )
- *         Created Jun 9, 2003 11:03:01 AM
+ * @author tm_jee 
+ * @version $Date$ $Id$
  */
 public class DefaultActionValidatorManagerTest extends XWorkTestCase {
 
             fail("Validation error: " + ex.getMessage());
         }
     }
+    
+    public void testFieldErrorsOrder() throws Exception {
+    	ValidationOrderAction action = new ValidationOrderAction();
+    	actionValidatorManager.validate(action, "actionContext");
+    	Map fieldErrors = action.getFieldErrors();
+    	Iterator i = fieldErrors.entrySet().iterator();
+    	
+    	assertNotNull(fieldErrors);
+    	assertEquals(fieldErrors.size(), 12);
+    	
+    	
+    	Map.Entry e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "username");
+    	assertEquals(((List)e.getValue()).get(0), "username required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "password");
+    	assertEquals(((List)e.getValue()).get(0), "password required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "confirmPassword");
+    	assertEquals(((List)e.getValue()).get(0), "confirm password required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "firstName");
+    	assertEquals(((List)e.getValue()).get(0), "first name required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "lastName");
+    	assertEquals(((List)e.getValue()).get(0), "last name required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "city");
+    	assertEquals(((List)e.getValue()).get(0), "city is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "province");
+    	assertEquals(((List)e.getValue()).get(0), "province is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "country");
+    	assertEquals(((List)e.getValue()).get(0), "country is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "postalCode");
+    	assertEquals(((List)e.getValue()).get(0), "postal code is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "email");
+    	assertEquals(((List)e.getValue()).get(0), "email is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "website");
+    	assertEquals(((List)e.getValue()).get(0), "website is required");
+    	
+    	e = (Map.Entry) i.next();
+    	assertEquals(e.getKey(), "passwordHint");
+    	assertEquals(((List)e.getValue()).get(0), "password hint is required");
+    	
+    }
 }