Anonymous committed 1cce4e6

client side validation works even when a visitor field is null


Comments (0)

Files changed (3)


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


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


 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.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 =;
+                                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
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.