You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2005/05/29 05:08:12 UTC
svn commit: r178920 -
/struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java
Author: dgeary
Date: Sat May 28 20:08:11 2005
New Revision: 178920
URL: http://svn.apache.org/viewcvs?rev=178920&view=rev
Log:
The s:validatorScript tag (which must come after all s:commonsValidator tags) has a component sitting behind it that walks the component tree and generates JavaScript for all the validators in the tree. It discovers validators in a private findCommonsValidators method. I modified that method to look for required validators and set the associated component's required property to true.
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java?rev=178920&r1=178919&r2=178920&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java Sat May 28 20:08:11 2005
@@ -43,19 +43,19 @@
// -------------------------------------------------------- Private Variables
-
+
/**
* <p>A map of validators, representing all of the Commons Validators
- * attached to components in the current component hierarchy.
- * The keys of the map are validator type names. The values are
- * maps from IDs to CommonsValidator objects.</p>
+ * attached to components in the current component hierarchy.
+ * The keys of the map are validator type names. The values are
+ * maps from IDs to CommonsValidator objects.</p>
*/
private Map validators = new LinkedHashMap();
/**
* <p>The component renders itself; therefore, this
- * method returns null.
+ * method returns null.
*/
public String getRendererType() {
return null;
@@ -64,8 +64,8 @@
/**
* <p>Returns the component's family. In this case,
- * the component is not associated with a family,
- * so this method returns null.
+ * the component is not associated with a family,
+ * so this method returns null.
*/
public String getFamily() {
return null;
@@ -74,10 +74,10 @@
/**
* <p>Registers a validator according to type and id.
- *
- * @param type The type of the validator
- * @param id The validator's identifier
- * @param v The Commons validator associated with the id and type
+ *
+ * @param type The type of the validator
+ * @param id The validator's identifier
+ * @param v The Commons validator associated with the id and type
*/
private void addValidator(String type, String id, CommonsValidator v) {
Map map = (Map) validators.get(type);
@@ -91,10 +91,10 @@
/**
* <p>Finds all of the Commons validators for all of the components
- * in a component hierarchy.
- *
- * @param c The component at the root of the component tree
- * @param context The FacesContext for this request
+ * in a component hierarchy.
+ *
+ * @param c The component at the root of the component tree
+ * @param context The FacesContext for this request
*/
private void findCommonsValidators(UIComponent c, FacesContext context) {
if (c instanceof EditableValueHolder) {
@@ -106,8 +106,17 @@
if (!Boolean.FALSE.equals(v.getClient())) {
String id = c.getClientId(context);
addValidator(v.getType(), id, v);
+
+ // Fields with empty values are not validated, so
+ // we force the issue here by setting the component's
+ // required attribute to true.
+
+ if("required".equals(v.getType())) {
+ h.setRequired(true);
+ }
+
ValidatorAction action = v.getValidatorAction();
- List list = action.getDependencyList();
+ List list = action.getDependencyList();
Iterator iter = list.iterator();
while (iter.hasNext()) {
String type = (String) iter.next();
@@ -128,8 +137,8 @@
/**
* <p>Write the start of the script for client-side validation.
- *
- * @param writer A response writer
+ *
+ * @param writer A response writer
*/
private void writeScriptStart(ResponseWriter writer) throws IOException {
writer.startElement("script", this);
@@ -141,8 +150,8 @@
/**
* <p>Write the end of the script for client-side validation.
- *
- * @param writer A response writer
+ *
+ * @param writer A response writer
*/
private void writeScriptEnd(ResponseWriter writer) throws IOException {
writer.write("\n-->\n");
@@ -152,9 +161,9 @@
/**
* <p>Returns the name of the JavaScript function, specified in
- * the JSP page (presumably), that validates this JSP page's form.
- *
- * @param action A Validator action
+ * the JSP page (presumably), that validates this JSP page's form.
+ *
+ * @param action A Validator action
*/
private static String getJavaScriptFunctionName(ValidatorAction action) {
StringTokenizer tokenizer = new StringTokenizer(
@@ -167,10 +176,10 @@
/**
* <p>Returns the name of the JavaScript function, specified in
- * the JSP page (presumably), that validates this JSP page's form.
- *
- * @param writer A response writer
- * @param context The FacesContext for this request
+ * the JSP page (presumably), that validates this JSP page's form.
+ *
+ * @param writer A response writer
+ * @param context The FacesContext for this request
*/
private void writeValidationFunctions(ResponseWriter writer,
FacesContext context) throws IOException {
@@ -234,11 +243,11 @@
/**
* <p>Writes the JavaScript parameters for the client-side
- * validation code.
- *
- * @param writer A response writer
- * @param context The FacesContext for this request
- * @param v The Commons validator
+ * validation code.
+ *
+ * @param writer A response writer
+ * @param context The FacesContext for this request
+ * @param v The Commons validator
*/
public void writeJavaScriptParams(ResponseWriter writer,
FacesContext context, String id, CommonsValidator v) throws IOException {
@@ -268,11 +277,11 @@
/**
* <p>Begin encoding for this component. This method
- * finds all Commons validators attached to components
- * in the current component hierarchy and writes out
- * JavaScript code to invoke those validators, in turn.
- *
- * @param context The FacesContext for this request
+ * finds all Commons validators attached to components
+ * in the current component hierarchy and writes out
+ * JavaScript code to invoke those validators, in turn.
+ *
+ * @param context The FacesContext for this request
*/
public void encodeBegin(FacesContext context) throws IOException {
String id = getClientId(context);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org