You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by ws...@apache.org on 2006/11/06 23:39:20 UTC

svn commit: r471907 - in /shale/framework/trunk/shale-apps/shale-usecases/src/main: java/org/apache/shale/usecases/validator/ resources/org/apache/shale/usecases/view/ webapp/WEB-INF/ webapp/validator/

Author: wsmoak
Date: Mon Nov  6 14:39:18 2006
New Revision: 471907

URL: http://svn.apache.org/viewvc?view=rev&rev=471907
Log:
Adding an example of a custom validation rule to the use cases app.  'Priority' must be an even integer.
Unfortunately, it doesn't quite work.  Entering an odd number causes a NPE when it tries to format the message.
SHALE-325

Added:
    shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java   (with props)
    shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml   (with props)
Modified:
    shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/Procedure.java
    shale/framework/trunk/shale-apps/shale-usecases/src/main/resources/org/apache/shale/usecases/view/Bundle.properties
    shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/web.xml
    shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/validator/test.jsp

Added: shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java?view=auto&rev=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java (added)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java Mon Nov  6 14:39:18 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.usecases.validator;
+
+/**
+ *  Custom commons-validator utility
+ *
+ */
+public class CustomValidationUtil {
+
+    /**
+     * Validation method which determines whether an integer is even.
+     * 
+     * @param value the integer value to be tested
+     * @return true if the supplied value is even, false otherwise
+     */
+    public static boolean isEven( int value ) {
+       return value % 2 == 0;
+    }
+
+}
+

Propchange: shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/CustomValidationUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/Procedure.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/Procedure.java?view=diff&rev=471907&r1=471906&r2=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/Procedure.java (original)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/validator/Procedure.java Mon Nov  6 14:39:18 2006
@@ -56,7 +56,17 @@
         this.minAmt = minAmt;
         this.maxAmt = maxAmt;
     }
-
+    
+    private int priority;
+    
+    public void setPriority(int newValue) {
+        priority = newValue;
+    }
+    
+    public int getPriority() {
+        return priority;
+    }
+    
     /**
      * @return procedure code
      */

Modified: shale/framework/trunk/shale-apps/shale-usecases/src/main/resources/org/apache/shale/usecases/view/Bundle.properties
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/resources/org/apache/shale/usecases/view/Bundle.properties?view=diff&rev=471907&r1=471906&r2=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/resources/org/apache/shale/usecases/view/Bundle.properties (original)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/resources/org/apache/shale/usecases/view/Bundle.properties Mon Nov  6 14:39:18 2006
@@ -108,6 +108,7 @@
 prompt.username=Username:
 prompt.creditCardNumber=Credit Card Number
 prompt.expirationDate=Expiration Date
+prompt.priority=Priority
 
 # Locale Selection Labels and Messages
 select.mismatch=You selected non-supported locale {0}, so no change was made
@@ -168,6 +169,7 @@
 validate.test.unknown.credit.card.type=Unknown Credit Card Type
 validate.test.bad.expiration.date=Bad Expiration Date. Enter the date in this format: mm/dd/yyyy
 validate.test.description=This form has six validators, all implemented with s:commonsValidator:<p><ul><li>Amount: <strong>floatRange</strong> (server)<li>Credit Card Number: <strong>required</strong> (server) <strong>mask</strong> ([4-6].*) (client) and <strong>creditCard</strong> (server)<li>Expiration Date: <strong>required</strong> (client) <strong>date</strong> (server)</ul><p>Note: because of the Credit Card Number field's mix of client- and server-side validators, entering "33" in the field results in a JavaScript alert (because the mask validator catches it), but entering "55" results in server-side validation and a subsequent error message displayed in the form.<p>See the Apache Commons Validator documentation for more information about other available validators.
+validate.test.not.even={0} is not an even number.
 
 # Tiles
 tiles.test.title=Using Tiles with Shale

Added: shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml?view=auto&rev=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml (added)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml Mon Nov  6 14:39:18 2006
@@ -0,0 +1,50 @@
+<!DOCTYPE form-validation PUBLIC
+          "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
+          "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
+<form-validation>
+
+    <!--
+     Licensed to the Apache Software Foundation (ASF) under one or more
+     contributor license agreements.  See the NOTICE file distributed with
+     this work for additional information regarding copyright ownership.
+     The ASF licenses this file to you under the Apache License, Version 2.0
+     (the "License"); you may not use this file except in compliance with
+     the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+    -->
+
+   <global>
+       <validator name="evenInteger"
+             classname="org.apache.shale.usecases.validator.CustomValidationUtil"
+             method="isEven"
+             methodParams="int"
+             msg="validate.test.not.even">
+       </validator>
+   </global>
+
+    <formset>
+
+        <!-- the 'form name' is always 'org.apache.shale.validator' plus the 'validator name' -->
+        <form name="org.apache.shale.validator.evenInteger">
+
+            <!-- the 'field property' always matches the 'validator name' -->
+            <field property="evenInteger">
+
+                <!-- validation error message replacement parameters -->
+                <arg position="0" name="message" key="submittedValue" resource="false"/>
+
+                <!-- validation method parameters -->
+                <arg position="0" name="parameter" key="submittedValue" resource="false"/>
+
+            </field>
+        </form>
+    </formset>
+
+</form-validation>
\ No newline at end of file

Propchange: shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/custom-rules.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/web.xml?view=diff&rev=471907&r1=471906&r2=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/web.xml (original)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/web.xml Mon Nov  6 14:39:18 2006
@@ -38,6 +38,15 @@
     <param-name>org.apache.commons.chain.CONFIG_WEB_RESOURCE</param-name>
     <param-value>/WEB-INF/chain-config.xml</param-value>
   </context-param>
+    
+    <!-- Shale Validator Configuration Resources -->
+    <context-param>
+       <param-name>org.apache.shale.validator.VALIDATOR_RULES</param-name>
+       <param-value>
+           /org/apache/shale/validator/validator-rules.xml,
+           /WEB-INF/custom-rules.xml
+       </param-value>
+    </context-param>
 
   <!-- Spring ApplicationContext Configuration -->
   <context-param>

Modified: shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/validator/test.jsp
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/validator/test.jsp?view=diff&rev=471907&r1=471906&r2=471907
==============================================================================
--- shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/validator/test.jsp (original)
+++ shale/framework/trunk/shale-apps/shale-usecases/src/main/webapp/validator/test.jsp Mon Nov  6 14:39:18 2006
@@ -219,6 +219,47 @@
 
     </h:form>
 </vc:subview>
+  
+  <br/><br/>
+  <p>The third part of this example deals with using custom validation rules.  
+      Priority must be an even integer.</p>
+  
+  <p>TODO:  Fix NPE when an odd integer is entered.</p>
+
+  <f:subview id="cvrSubview">
+      <h:form id="cvrForm" onsubmit="return validateForm(this);">
+
+          <h:panelGrid    columns="3">
+
+          <h:outputText value="#{messages['prompt.priority']}"/>
+          <h:inputText     id="priority"
+                        value="#{priority}">
+              <val:commonsValidator
+                          type="required"
+                          arg="#{messages['prompt.priority']}"
+                       server="true"
+                       client="false"/>
+              <val:commonsValidator
+                     type="evenInteger"
+                   server="true"
+                   client="false"/>
+          </h:inputText>
+           <h:message           for="priority" styleClass="errors"/>
+
+     </h:panelGrid>
+
+          <br/><br/>
+
+          <h:commandButton value="Submit" action="validate$thankYou"/>
+
+          <br/><br/>
+          <h:commandLink
+                   immediate="true"
+                       value="#{messages['usecases.primary']}"
+                      action="usecases$toplevel"/>
+
+      </h:form>
+  </f:subview>
 
 <val:validatorScript functionName="validateForm"/>