You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2003/11/18 01:44:32 UTC
cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/struts ValidatorTool.java
nbubna 2003/11/17 16:44:32
Modified: src/java/org/apache/velocity/tools/struts ValidatorTool.java
Log:
add auto-form-name-lookup for convenience and don't encourage stateful use in javadoc
Revision Changes Path
1.5 +27 -7 jakarta-velocity-tools/src/java/org/apache/velocity/tools/struts/ValidatorTool.java
Index: ValidatorTool.java
===================================================================
RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/struts/ValidatorTool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ValidatorTool.java 6 Nov 2003 00:26:54 -0000 1.4
+++ ValidatorTool.java 18 Nov 2003 00:44:32 -0000 1.5
@@ -73,6 +73,8 @@
import org.apache.commons.validator.ValidatorUtil;
import org.apache.commons.validator.Var;
+import org.apache.struts.Globals;
+import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
@@ -88,11 +90,6 @@
* <p>Usage:
* <pre>
* Template example:
- * <!-- javascript form validation -->
- * $validator.setFormName("myForm")
- * $validator.javascript <-- spits out the dynamic javascript
- *
- * or simply
*
* $validator.getJavascript("nameOfYourForm")
*
@@ -172,6 +169,15 @@
{
this.xhtml = b.booleanValue();
}
+
+ /* Is there a mapping associated with this request? */
+ ActionConfig config =
+ (ActionConfig)request.getAttribute(Globals.MAPPING_KEY);
+ if (config != null)
+ {
+ /* Is there a form bean associated with this mapping? */
+ this.formName = config.getAttribute();
+ }
}
@@ -374,10 +380,24 @@
/****************** methods that aren't just accessors ***************/
/**
+ * Render the JavaScript for to perform validations based on
+ * the form name already set the form name via {@link #setFormName}
+ * or the form name attribute of the action mapping associated
+ * with the current request (if such exists).
+ *
+ * @return the javascript for the current form
+ * @throws Exception
+ */
+ public String getJavascript() throws Exception
+ {
+ return getJavascript(getFormName());
+ }
+
+ /**
* Render the JavaScript for to perform validations based on the form name.
*
* @param formName the key (form name)
- * @return the Javascript for the specified key
+ * @return the Javascript for the specified form
* @throws Exception
*/
public String getJavascript(String formName) throws Exception
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org