Commits

Anonymous committed 7799900

XW-410
- RepopulateConversionErrorFieldValidatorSupport not restoring field values when dealing with domain objects.
(apply Derek's fix + test cases)

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2/src@1117e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

java/com/opensymphony/xwork/validator/validators/RepopulateConversionErrorFieldValidatorSupport.java

 			String[] tmpValue = (String[]) value;
 			if (tmpValue != null && (tmpValue.length > 0) ) {
 				doExprOverride = true;
-				fakeParams.put(fieldName, "'"+tmpValue[0]+"'");
+				fakeParams.put(fullFieldName, "'"+tmpValue[0]+"'");
 			}
 			else {
 				_log.warn("value is an empty array of String or with first element in it as null ["+value+"], will not repopulate conversion error ");
 		else if (value instanceof String) {
 			String tmpValue = (String) value;
 			doExprOverride = true;
-			fakeParams.put(fieldName, "'"+tmpValue+"'");
+			fakeParams.put(fullFieldName, "'"+tmpValue+"'");
 		}
 		else {
 			// opps... it should be 

test/com/opensymphony/xwork/validator/RepopulateConversionErrorFieldValidatorSupportTest.java

 import com.opensymphony.xwork.mock.MockActionInvocation;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.validator.validators.RepopulateConversionErrorFieldValidatorSupport;
+import com.opensymphony.xwork.validator.DelegatingValidatorContext;
 
 import junit.framework.TestCase;
 
 
 	
 	InternalRepopulateConversionErrorFieldValidatorSupport validator1;
+	InternalRepopulateConversionErrorFieldValidatorSupport validator2;
 	ActionSupport action;
 	
+	public void testUseFullFieldName() throws Exception {
+		validator2.setRepopulateField("true");
+		validator2.validate(action);
+		
+		ActionContext.getContext().getActionInvocation().invoke();
+		Object valueFromStack1 = ActionContext.getContext().getValueStack().findValue("someFieldName", String.class);
+		Object valueFromStack2 = ActionContext.getContext().getValueStack().findValue("xxxsomeFieldName", String.class);
+		
+		assertNull(valueFromStack1);
+		assertEquals(valueFromStack2, "some value");
+	}
+	
 	public void testGetterSetterGetsCalledApropriately1() throws Exception {
 		
 		validator1.setRepopulateField("true");
 			new InternalRepopulateConversionErrorFieldValidatorSupport();
 		validator1.setFieldName("someFieldName");
 		validator1.setValidatorContext(new DelegatingValidatorContext(action));
+		conversionErrors.put("xxxsomeFieldName", conversionErrorValue);
+		
+		validator2 = 
+			new InternalRepopulateConversionErrorFieldValidatorSupport();
+		validator2.setFieldName("someFieldName");
+		validator2.setValidatorContext(new DelegatingValidatorContext(action) {
+			public String getFullFieldName(String fieldName) {
+				return "xxx"+fieldName;
+			}
+		});
 	}
 	
 	protected void tearDown() throws Exception {