Commits

Anonymous committed 1cce4e6

client side validation works even when a visitor field is null

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@497573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (3)

src/example/com/opensymphony/webwork/example/JavascriptValidationAction.java

     String email;
     String url;
     Date date;
-    ValidatedBean bean = new ValidatedBean();
+    ValidatedBean bean;
 
     public String execute() throws Exception {
         return SUCCESS;

src/java/com/opensymphony/webwork/validators/JavaScriptDateRangeFieldValidator.java

     //~ Methods ////////////////////////////////////////////////////////////////
 
     public String validationScript(Map parameters) {
-        return "alert('foo')";
+        return "";
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractUITag.java

 import com.opensymphony.xwork.ModelDriven;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.validator.*;
+import ognl.OgnlRuntime;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.Template;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspException;
+import java.beans.PropertyDescriptor;
 import java.io.Writer;
 import java.util.HashMap;
 import java.util.Iterator;
                         Class realFieldClass = visitorValidator.getValidatedClass();
 
                         if (realFieldClass == null) {
-                            Object fieldValue = findValue(visitorValidator.getFieldName());
-
-                            if (fieldValue != null) {
-                                realFieldClass = fieldValue.getClass();
+                            for (Iterator iterator1 = getStack().getRoot().iterator(); iterator1.hasNext();) {
+                                Object o = iterator1.next();
+                                try {
+                                    PropertyDescriptor pd =
+                                            OgnlRuntime.getPropertyDescriptor(o.getClass(), visitorValidator.getFieldName());
+                                    realFieldClass = pd.getPropertyType();
+                                    break;
+                                } catch (Throwable t) {
+                                    // just keep trying
+                                }
                             }
                         }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.