You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/02/04 18:32:22 UTC

svn commit: r906576 - in /myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main: java/org/apache/myfaces/blank/ webapp/ webapp/WEB-INF/

Author: gpetracek
Date: Thu Feb  4 17:32:21 2010
New Revision: 906576

URL: http://svn.apache.org/viewvc?rev=906576&view=rev
Log:
hello-bv example

Added:
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloGroupValidationController.java
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation01.jsp
      - copied, changed from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form1.jsp
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation02.jsp
      - copied, changed from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form2.jsp
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/modelValidation01.jsp
      - copied, changed from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/violation.jsp
Removed:
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form1.jsp
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form2.jsp
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/violation.jsp
Modified:
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloWorldController.java
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/helloWorld.jsp
    myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/result.jsp

Added: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloGroupValidationController.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloGroupValidationController.java?rev=906576&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloGroupValidationController.java (added)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloGroupValidationController.java Thu Feb  4 17:32:21 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.myfaces.blank;
+
+import org.apache.myfaces.blank.domain.Person;
+import org.apache.myfaces.blank.validation.group.Admin;
+import org.apache.myfaces.blank.validation.group.User;
+import org.apache.myfaces.blank.validation.group.Address;
+import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
+import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
+
+/**
+ * A typical simple backing bean, that is backed to <code>helloworld.jsp</code>
+ */
+public class HelloGroupValidationController
+{
+    @BeanValidation.List({
+            @BeanValidation(viewIds = "/groupValidation01.jsp", useGroups = User.class),
+            @BeanValidation(viewIds = "/groupValidation02.jsp", useGroups = Admin.class),
+            @BeanValidation(viewIds = "/modelValidation01.jsp", useGroups = Admin.class),
+            @BeanValidation(viewIds = "/modelValidation01.jsp", useGroups = Address.class,
+                    modelValidation = @ModelValidation(isActive = true))
+    })
+    private Person person = new Person();
+
+    /**
+     * default empty constructor
+     */
+    public HelloGroupValidationController()
+    {
+    }
+
+    public String send()
+    {
+        //do real logic, return a string which will be used for the navigation system of JSF
+        return "success";
+    }
+
+    public Person getPerson()
+    {
+        return person;
+    }
+
+    public void setPerson(Person person)
+    {
+        this.person = person;
+    }
+}
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloWorldController.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloWorldController.java?rev=906576&r1=906575&r2=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloWorldController.java (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/java/org/apache/myfaces/blank/HelloWorldController.java Thu Feb  4 17:32:21 2010
@@ -19,25 +19,12 @@
 package org.apache.myfaces.blank;
 
 import org.apache.myfaces.blank.domain.Person;
-import org.apache.myfaces.blank.validation.group.Admin;
-import org.apache.myfaces.blank.validation.group.User;
-import org.apache.myfaces.blank.validation.group.Address;
-import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
-import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
 
 /**
  * A typical simple backing bean, that is backed to <code>helloworld.jsp</code>
  */
-
-//adds the default group on form1 in case of group validation* for properties which contain this bean in the path
-//in this case every value binding which starts with helloWorld e.g. #{helloWorld.person.firstName}
-//*in this example the User group is used
-@BeanValidation(viewIds = "/form1.jsp")
 public class HelloWorldController
 {
-    //adds the default group on form1 in case of group validation for properties which contain this property in the path
-    //in this case every value binding which starts with helloWorld.person e.g. #{helloWorld.person.firstName}
-    //@BeanValidation(viewIds = "/form1.jsp")
     private Person person = new Person();
 
     /**
@@ -53,13 +40,6 @@
         return "success";
     }
 
-    @BeanValidation.List({
-            @BeanValidation(viewIds = "/form1.jsp", useGroups = User.class),
-            @BeanValidation(viewIds = "/form2.jsp", useGroups = Admin.class),
-            @BeanValidation(viewIds = "/violation.jsp", useGroups = Admin.class),
-            @BeanValidation(viewIds = "/violation.jsp", useGroups = Address.class,
-                    modelValidation = @ModelValidation(isActive = true))
-    })
     public Person getPerson()
     {
         return person;

Modified: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/WEB-INF/faces-config.xml?rev=906576&r1=906575&r2=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/WEB-INF/faces-config.xml Thu Feb  4 17:32:21 2010
@@ -30,6 +30,12 @@
 		<managed-bean-scope>request</managed-bean-scope>
 	</managed-bean>
 	
+	<managed-bean>
+		<managed-bean-name>helloGroupValidationController</managed-bean-name>
+		<managed-bean-class>org.apache.myfaces.blank.HelloGroupValidationController</managed-bean-class>
+		<managed-bean-scope>request</managed-bean-scope>
+	</managed-bean>
+
 	<!-- navigation rules for helloWorld.jsp -->
 	<navigation-rule>
 		<from-view-id>*</from-view-id>
@@ -37,6 +43,18 @@
 			<from-outcome>success</from-outcome>
 			<to-view-id>/result.jsp</to-view-id>
 		</navigation-case>
+		<navigation-case>
+			<from-outcome>example01</from-outcome>
+			<to-view-id>/groupValidation01.jsp</to-view-id>
+		</navigation-case>
+		<navigation-case>
+			<from-outcome>example02</from-outcome>
+			<to-view-id>/groupValidation02.jsp</to-view-id>
+		</navigation-case>
+		<navigation-case>
+			<from-outcome>example03</from-outcome>
+			<to-view-id>/modelValidation01.jsp</to-view-id>
+		</navigation-case>
 	</navigation-rule>
 	
 	<!-- navigation rules for result.jsp -->

Copied: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation01.jsp (from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form1.jsp)
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation01.jsp?p2=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation01.jsp&p1=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form1.jsp&r1=906114&r2=906576&rev=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form1.jsp (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation01.jsp Thu Feb  4 17:32:21 2010
@@ -25,20 +25,24 @@
         <f:view>
             <h:form id="mainForm">
               <h:panelGrid columns="3">
-                <h:outputLabel for="first_name" value="First name:"/>
-                <h:inputText id="first_name" label="First name" value="#{helloWorld['person'].firstName}"/>
+                <h:outputLabel for="first_name" value="First name*:"/>
+                <h:inputText id="first_name" label="First name" value="#{helloGroupValidationController['person'].firstName}"/>
                 <h:message for="first_name" showSummary="true" showDetail="false"/>
 
-                <h:outputLabel for="last_name" value="Last name:"/>
-                <h:inputText id="last_name" label="Last name" value="#{helloWorld.person.lastName}"/>
+                <h:outputLabel for="last_name" value="Last name**:"/>
+                <h:inputText id="last_name" label="Last name" value="#{helloGroupValidationController.person.lastName}"/>
                 <h:message for="last_name" showSummary="true" showDetail="false"/>
 
-                <h:commandButton value="Press me" action="#{helloWorld.send}"/>
+                <h:commandButton value="Press me" action="#{helloGroupValidationController.send}"/>
                 <h:panelGroup/>
                 <h:panelGroup/>
               </h:panelGrid>
             </h:form>
             <h:messages globalOnly="true" showDetail="true" showSummary="false"/>
         </f:view>
+        <hr/>
+
+        * not required<br/>
+        ** not required; length of provided value: 3-6 characters
     </body>
 </html>

Copied: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation02.jsp (from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form2.jsp)
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation02.jsp?p2=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation02.jsp&p1=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form2.jsp&r1=906114&r2=906576&rev=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/form2.jsp (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/groupValidation02.jsp Thu Feb  4 17:32:21 2010
@@ -26,19 +26,23 @@
             <h:form id="mainForm">
               <h:panelGrid columns="3">
                 <h:outputLabel for="first_name" value="First name:"/>
-                <h:inputText id="first_name" label="First name" value="#{helloWorld['person'].firstName}"/>
+                <h:inputText id="first_name" label="First name" value="#{helloGroupValidationController['person'].firstName}"/>
                 <h:message for="first_name" showSummary="true" showDetail="false"/>
 
                 <h:outputLabel for="last_name" value="Last name:"/>
-                <h:inputText id="last_name" label="Last name" value="#{helloWorld.person.lastName}"/>
+                <h:inputText id="last_name" label="Last name" value="#{helloGroupValidationController.person.lastName}"/>
                 <h:message for="last_name" showSummary="true" showDetail="false"/>
 
-                <h:commandButton value="Press me" action="#{helloWorld.send}"/>
+                <h:commandButton value="Press me" action="#{helloGroupValidationController.send}"/>
                 <h:panelGroup/>
                 <h:panelGroup/>
               </h:panelGrid>
             </h:form>
             <h:messages globalOnly="true" showDetail="true" showSummary="false"/>
         </f:view>
+        <hr/>
+
+        * not required<br/>
+        ** not required; length of provided value: 3-12 characters
     </body>
 </html>

Modified: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/helloWorld.jsp
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/helloWorld.jsp?rev=906576&r1=906575&r2=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/helloWorld.jsp (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/helloWorld.jsp Thu Feb  4 17:32:21 2010
@@ -37,10 +37,15 @@
                 <h:panelGroup/>
                 <h:panelGroup/>
               </h:panelGrid>
+
+              <hr/>
+              <h:commandLink value="group validation example 1" action="example01" immediate="true"/><br/>
+              <h:commandLink value="group validation example 2" action="example02" immediate="true"/><br/>
+              <h:commandLink value="model validation example 1 (forced validation error)" action="example03" immediate="true"/><br/>
             </h:form>
         </f:view>
         <hr/>
-        * none blocking warn mode<br/>
+        * non blocking warn mode<br/>
         ** blocking error mode
     </body>
 </html>

Copied: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/modelValidation01.jsp (from r906114, myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/violation.jsp)
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/modelValidation01.jsp?p2=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/modelValidation01.jsp&p1=myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/violation.jsp&r1=906114&r2=906576&rev=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/violation.jsp (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/modelValidation01.jsp Thu Feb  4 17:32:21 2010
@@ -26,19 +26,25 @@
             <h:form id="mainForm">
               <h:panelGrid columns="3">
                 <h:outputLabel for="first_name" value="First name:"/>
-                <h:inputText id="first_name" label="First name" value="#{helloWorld['person'].firstName}"/>
+                <h:inputText id="first_name" label="First name" value="#{helloGroupValidationController['person'].firstName}"/>
                 <h:message for="first_name" showSummary="true" showDetail="false"/>
 
                 <h:outputLabel for="last_name" value="Last name:"/>
-                <h:inputText id="last_name" label="Last name" value="#{helloWorld.person.lastName}"/>
+                <h:inputText id="last_name" label="Last name" value="#{helloGroupValidationController.person.lastName}"/>
                 <h:message for="last_name" showSummary="true" showDetail="false"/>
 
-                <h:commandButton value="Press me" action="#{helloWorld.send}"/>
+                <h:commandButton value="Press me" action="#{helloGroupValidationController.send}"/>
                 <h:panelGroup/>
                 <h:panelGroup/>
               </h:panelGrid>
             </h:form>
             <h:messages globalOnly="true" showDetail="true" showSummary="false"/>
         </f:view>
+        <hr/>
+        it isn't possible to submit this form!<br/>
+        reason: model-validation is triggered -> address group is validated
+
+        * not required<br/>
+        ** not required; length of provided value: 3-12 characters
     </body>
 </html>

Modified: myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/result.jsp
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/result.jsp?rev=906576&r1=906575&r2=906576&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/result.jsp (original)
+++ myfaces/extensions/validator/trunk/examples/hello_bean-validation/src/main/webapp/result.jsp Thu Feb  4 17:32:21 2010
@@ -24,7 +24,7 @@
     <body>
         <f:view>
             <h:form id="mainForm">
-                <h2><h:outputText value="Hello #{helloWorld.person.firstName} #{helloWorld.person.lastName}. We hope you enjoy Apache MyFaces Extensions Validator!"/></h2>
+                <h2><h:outputText value="Hello #{helloWorld.person.firstName} #{helloWorld.person.lastName}#{helloGroupValidationController.person.firstName} #{helloGroupValidationController.person.lastName}. We hope you enjoy Apache MyFaces Extensions Validator!"/></h2>
                 <h:commandLink action="back">
                     <h:outputText value="Home"/>
                 </h:commandLink>