You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by al...@apache.org on 2010/08/08 00:02:23 UTC

svn commit: r983317 - in /myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main: java/org/apache/myfaces/html5/examples/showcase/beans/ java/org/apache/myfaces/html5/examples/showcase/validator/ webapp/WEB-INF/ webapp/inputText/

Author: aliok
Date: Sat Aug  7 22:02:22 2010
New Revision: 983317

URL: http://svn.apache.org/viewvc?rev=983317&view=rev
Log:
Added example of driving client-side pattern by custom JSF validator

Added:
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/PartNumberValidator.java
Modified:
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/beans/InputTextBean.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/WEB-INF/web.xml
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/inputText/inputText04.xhtml

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/beans/InputTextBean.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/beans/InputTextBean.java?rev=983317&r1=983316&r2=983317&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/beans/InputTextBean.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/beans/InputTextBean.java Sat Aug  7 22:02:22 2010
@@ -45,6 +45,7 @@ public class InputTextBean
     private String someParam;
     private String secondParam;
     private String thirdParam;
+    private String fourthParam;
 
     public List<SelectItem> getSuggestionItems()
     {
@@ -206,6 +207,16 @@ public class InputTextBean
         this.thirdParam = thirdParam;
     }
 
+    public String getFourthParam()
+    {
+        return fourthParam;
+    }
+
+    public void setFourthParam(String fourthParam)
+    {
+        this.fourthParam = fourthParam;
+    }
+
     public int getResult()
     {
         return ((firstNumber == null) ? 0 : firstNumber) * ((secondNumber == null) ? 0 : secondNumber);

Added: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/PartNumberValidator.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/PartNumberValidator.java?rev=983317&view=auto
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/PartNumberValidator.java (added)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/java/org/apache/myfaces/html5/examples/showcase/validator/PartNumberValidator.java Sat Aug  7 22:02:22 2010
@@ -0,0 +1,37 @@
+package org.apache.myfaces.html5.examples.showcase.validator;
+
+import java.util.regex.Pattern;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.html5.component.api.validation.ClientSidePatternProvider;
+
+@FacesValidator(value="partNumberValidator")
+public class PartNumberValidator implements Validator, ClientSidePatternProvider
+{
+    private static final String PATTERN = "[0-9][A-Z]{3}";
+
+    public String getPattern()
+    {
+        return PATTERN;
+    }
+
+    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
+    {
+        if(value == null)
+            return;
+        if (value instanceof String)
+        {
+            String partNum = (String) value;
+            
+            if(! Pattern.matches(PATTERN, partNum)){
+                throw new ValidatorException(new FacesMessage("Provided value is not a part number"));
+            }
+        }
+    }
+}

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/WEB-INF/web.xml?rev=983317&r1=983316&r2=983317&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/WEB-INF/web.xml Sat Aug  7 22:02:22 2010
@@ -35,7 +35,7 @@
     <!-- Necessary to run with jetty:run -->
     <context-param>
         <param-name>org.apache.myfaces.annotation.SCAN_PACKAGES</param-name>
-        <param-value>org.apache.myfaces.html5.examples.showcase.beans</param-value>
+        <param-value>org.apache.myfaces.html5.examples.showcase</param-value>
     </context-param>
 
 	<servlet>

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/inputText/inputText04.xhtml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/inputText/inputText04.xhtml?rev=983317&r1=983316&r2=983317&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/inputText/inputText04.xhtml (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-examples/src/main/webapp/inputText/inputText04.xhtml Sat Aug  7 22:02:22 2010
@@ -55,6 +55,12 @@
                     <hx:inputText id="anotherTextIT" value="#{inputTextBean.secondParam}" required="true" title="A prefix is must be minimum 3 characters, maximum 5 characters.">
                         <f:validateLength minimum="3" maximum="5" />
                     </hx:inputText>
+                    
+                    <label>Support for custom validators:</label>
+                    <hx:inputText id="someAnotherTextIT" value="#{inputTextBean.fourthParam}" required="true" 
+                        title="A part number is a digit followed by three uppercase letters.">
+                        <f:validator validatorId="partNumberValidator" />
+                    </hx:inputText>
 		    	
 		    		<h:outputText />
 			    	<h:commandButton action="none"/>