Commits

plightbo  committed 46b1677

* more javascript client validation implementations (not finished tho)
* readme and changelog template based on Bill's jira issue
* javascript validation example has visitor example
* conversion errors now automatically have their original values displayed
* new feature in the valuestack: setPropertyOverrides() allows expressions to be
overriden (perfect for conversion error reporting stuff)

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

  • Participants
  • Parent commits 454c237

Comments (0)

Files changed (3)

File src/java/com/opensymphony/xwork/interceptor/ConversionErrorInterceptor.java

 
 import java.util.Iterator;
 import java.util.Map;
+import java.util.HashMap;
 
 
 /**
 public class ConversionErrorInterceptor extends AroundInterceptor {
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    public static final String ORIGINAL_PROPERTY_OVERRIDE = "original.property.override";
+
     protected void after(ActionInvocation dispatcher, String result) throws Exception {
     }
 
         Map conversionErrors = invocationContext.getConversionErrors();
         OgnlValueStack stack = invocationContext.getValueStack();
 
+        HashMap fakie = null;
         for (Iterator iterator = conversionErrors.entrySet().iterator();
                 iterator.hasNext();) {
             Map.Entry entry = (Map.Entry) iterator.next();
                 String message = XWorkConverter.getConversionErrorMessage(propertyName, stack);
                 String addFieldErrorExpression = "addFieldError('" + propertyName + "','" + message + "')";
                 stack.findValue(addFieldErrorExpression);
+
+                if (fakie == null) {
+                    fakie = new HashMap();
+                }
+                fakie.put(propertyName, getOverrideExpr(invocation, value));
             }
         }
+
+        if (fakie != null) {
+            // if there were some errors, put the original (fake) values in place right before the result
+            stack.getContext().put(ORIGINAL_PROPERTY_OVERRIDE, fakie);
+            invocation.addPreResultListener(new PreResultListener() {
+                public void beforeResult(ActionInvocation invocation, String resultCode) {
+                    Map fakie = (Map) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);
+                    if (fakie != null) {
+                        invocation.getStack().setPropertyOverrides(fakie);
+                    }
+                }
+            });
+        }
+    }
+
+    protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
+        return "'" + value + "'";
     }
 
     protected boolean shouldAddError(String propertyName, Object value) {

File src/java/com/opensymphony/xwork/util/OgnlValueStack.java

     CompoundRoot root;
     transient Map context;
     Class defaultType;
+    Map overrides;
 
     //~ Constructors ///////////////////////////////////////////////////////////
 
                 return null;
             }
 
+            if (overrides != null && overrides.containsKey(expr)) {
+                expr = (String) overrides.get(expr);
+            }
+
             if (defaultType != null) {
                 return findValue(expr, defaultType);
             }
                 return null;
             }
 
+            if (overrides != null && overrides.containsKey(expr)) {
+                expr = (String) overrides.get(expr);
+            }
+
             return Ognl.getValue(OgnlUtil.compile(expr), context, root, asType);
         } catch (OgnlException e) {
             return null;
 
         return aStack;
     }
+
+    public void setPropertyOverrides(Map overrides) {
+        this.overrides = overrides;
+    }
 }

File src/java/com/opensymphony/xwork/validator/validators/AbstractRangeValidator.java

     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void validate(Object object) throws ValidationException {
-        Comparable value = (Comparable) this.getFieldValue(getFieldName(), object);
+        Object obj = getFieldValue(getFieldName(), object);
+        Comparable value = (Comparable) obj;
 
         // if there is no value - don't do comparison
         // if a value is required, a required validator should be added to the field