1. opensymphony
  2. webwork

Commits

plightbo  committed 0025868

more javascript-based client side validation:
* commands can be specified at runtime and honor doXxx and xxx (foo!default) (WW-502)
* the client side validation uses the action you are submitting to, not the current one

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

  • Participants
  • Parent commits 3e0f167
  • Branches master

Comments (0)

Files changed (9)

File src/etc/taglib.tld

View file
  • Ignore whitespace
             <rtexprvalue>true</rtexprvalue>
         </attribute>
         <attribute>
+            <name>namespace</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+        </attribute>
+        <attribute>
             <name>method</name>
             <required>false</required>
             <rtexprvalue>true</rtexprvalue>

File src/example/com/opensymphony/webwork/example/JavascriptValidationAction-javascriptValidation-validation.xml

View file
  • Ignore whitespace
+<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">
+<validators>
+    <field name="test">
+        <field-validator type="requiredstring">
+            <message>You must enter a string.</message>
+        </field-validator>
+    </field>
+</validators>

File src/example/com/opensymphony/webwork/example/JavascriptValidationAction-validation.xml

  • Ignore whitespace
-<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">
-<validators>
-    <field name="test">
-        <field-validator type="requiredstring">
-            <message>You must enter a string.</message>
-        </field-validator>
-    </field>
-</validators>

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

View file
  • Ignore whitespace
         return SUCCESS;
     }
 
+    public String doDefault() {
+        return INPUT;
+    }
+
     public String getTest() {
         return test;
     }

File src/java/com/opensymphony/webwork/default.properties

View file
  • Ignore whitespace
 ### Load custom property files (does not override webwork.properties!)
 #webwork.custom.properties=application,com/webwork/extension/custom
 
+# extension for actions
+webwork.action.extension=action
 
 ### Standard UI theme
 # Change this to reflect which path should be used for JSP control tag templates by default

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

View file
  • Ignore whitespace
 
         // now let's do some JavaScript stuff. or something
         if (tag != null) {
-            ActionInvocation ai = (ActionInvocation) stack.getContext().get(ActionContext.ACTION_INVOCATION);
-            Action action = ai.getAction();
-            String actionName = ai.getProxy().getActionName();
-            List validators = ActionValidatorManager.getValidators(action.getClass(), actionName);
+            List validators = ActionValidatorManager.getValidators(tag.getActionClass(), tag.getActionName());
             for (Iterator iterator = validators.iterator(); iterator.hasNext();) {
                 Validator validator = (Validator) iterator.next();
                 if (validator instanceof FieldValidator)

File src/java/com/opensymphony/webwork/views/jsp/ui/FormTag.java

View file
  • Ignore whitespace
 package com.opensymphony.webwork.views.jsp.ui;
 
 import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.validators.ScriptValidationAware;
 import com.opensymphony.webwork.views.util.UrlHelper;
 
 import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.validator.FieldValidator;
 import com.opensymphony.xwork.util.OgnlValueStack;
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
     String actionAttr;
+    String namespaceAttr;
     String enctypeAttr;
     String methodAttr;
     String validateAttr;
     Map fieldValidators;
     Map fieldParameters;
+    Class actionClass;
+    String actionName;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         this.actionAttr = action;
     }
 
+    public void setNamespace(String namespace) {
+        this.namespaceAttr = namespace;
+    }
+
     public String getDefaultOpenTemplate() {
         return OPEN_TEMPLATE;
     }
                 response = ServletActionContext.getResponse();
             }
 
-            Object actionObj = findValue(actionAttr, String.class);
+            String action = (String) findValue(actionAttr, String.class);
+            String namespace = (String) findValue(namespaceAttr, String.class);
+            if (namespace == null) {
+                namespace = "";
+            }
 
-            if (actionObj != null) {
-                String result = UrlHelper.buildUrl(actionObj.toString(), request, response, null);
+            ActionConfig actionConfig = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, action);
+            if (actionConfig != null) {
+                actionClass = actionConfig.getClazz();
+                actionName = action;
+                String result = UrlHelper.buildUrl(namespace + "/" + action + "." + Configuration.get("webwork.action.extension"), request, response, null);
+                addParameter("action", result);
+            } else if (action != null) {
+                String result = UrlHelper.buildUrl(action, request, response, null);
                 addParameter("action", result);
             }
         }
     public Map getFieldParameters() {
         return fieldParameters;
     }
+
+    public Class getActionClass() {
+        return actionClass;
+    }
+
+    public String getActionName() {
+        return actionName;
+    }
 }

File src/webapp/default.jsp

View file
  • Ignore whitespace
         with expression validation
     </li>
 
-    <li><a href="javascriptValidation.action">Validation that uses JavaScript to do client side support</a></li>
+    <li><a href="javascriptValidation!default.action">Validation that uses JavaScript to do client side support</a></li>
 </ul>
 
 

File src/webapp/javascript-input.jsp

View file
  • Ignore whitespace
     </head>
     
     <body>
-        <ww:form name="'test'" action="javascript" validate="true" >
+        <ww:form name="'test'" action="'javascriptValidation'" validate="true" >
             <ww:textfield label="'Can't be empty'" name="'test'" required="true"/>
             <ww:submit value="'Submit'"/>
         </ww:form>