[seam-commits] Seam SVN: r12686 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/component and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu May 6 12:06:12 EDT 2010


Author: lincolnthree
Date: 2010-05-06 12:06:11 -0400 (Thu, 06 May 2010)
New Revision: 12686

Modified:
   modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
Log:
Additional developer feedback messages, and some corrections in the documentation.

Modified: modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml
===================================================================
--- modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml	2010-05-06 14:32:43 UTC (rev 12685)
+++ modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml	2010-05-06 16:06:11 UTC (rev 12686)
@@ -43,9 +43,9 @@
 			Performing cross-field form validation is simple - just place the <s:validateForm> component
 			in the form you wish to validate, then attach your custom Validator.
 			<programlisting><![CDATA[<h:form id="locationForm">
-     <h:inputText id="city" value="#{bean.author}" />
-     <h:inputText id="state" value="#{bean.title}" />
-     <h:inputText id="zip" value="#{bean.text}" />
+     <h:inputText id="city" value="#{bean.city}" />
+     <h:inputText id="state" value="#{bean.state}" />
+     <h:inputText id="zip" value="#{bean.zip}" />
      <h:commandButton id="submit" value="Submit" action="#{bean.submitPost}" />
                   
       <s:validateForm validatorId="locationValidator" />
@@ -103,9 +103,9 @@
 			ID alias (see below.) 
 			
 			<programlisting><![CDATA[<h:form id="locationForm">
-     <h:inputText id="cityId" value="#{bean.author}" />
-     <h:inputText id="stateId" value="#{bean.title}" />
-     <h:inputText id="zip" value="#{bean.text}" />
+     <h:inputText id="cityId" value="#{bean.city}" />
+     <h:inputText id="stateId" value="#{bean.state}" />
+     <h:inputText id="zip" value="#{bean.zip}" />
      <h:commandButton id="submit" value="Submit" action="#{bean.submitPost}" />
                   
       <s:validateForm fields="city=cityId state=stateId" validatorId="locationValidator" />

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java	2010-05-06 14:32:43 UTC (rev 12685)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java	2010-05-06 16:06:11 UTC (rev 12686)
@@ -35,7 +35,6 @@
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
 import javax.faces.component.UIInput;
-import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.inject.Inject;
@@ -65,7 +64,7 @@
    public void interceptComponentTree(@Observes @Before final UIValidateForm event)
    {
       validator = event;
-      form = locateForm(event);
+      form = validator.locateForm();
       components = locateAliasedComponents(event);
    }
 
@@ -124,20 +123,6 @@
       return parameterName;
    }
 
-   private UIForm locateForm(final UIComponent component)
-   {
-      UIComponent parent = component.getParent();
-      while (!(parent instanceof UIForm))
-      {
-         parent = parent.getParent();
-         if ((parent == null) || (parent instanceof UIViewRoot))
-         {
-            throw new IllegalStateException("The form validator must be placed within a UIForm");
-         }
-      }
-      return (UIForm) parent;
-   }
-
    public HashMap<String, UIInput> locateAliasedComponents(final UIValidateForm validator)
    {
       HashMap<String, UIInput> result = new HashMap<String, UIInput>();

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java	2010-05-06 14:32:43 UTC (rev 12685)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java	2010-05-06 16:06:11 UTC (rev 12686)
@@ -23,14 +23,13 @@
 package org.jboss.seam.faces.component;
 
 import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.enterprise.util.AnnotationLiteral;
 import javax.faces.component.FacesComponent;
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
 import javax.faces.component.UIInput;
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PostValidateEvent;
 import javax.faces.event.PreValidateEvent;
@@ -40,8 +39,6 @@
 import org.jboss.seam.faces.event.qualifier.After;
 import org.jboss.seam.faces.event.qualifier.Before;
 import org.jboss.seam.faces.util.BeanManagerAccessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
@@ -65,10 +62,6 @@
    private String validatorId = "";
    private String fields = "";
 
-   private final Logger log = LoggerFactory.getLogger(UIValidateForm.class);
-
-   private final Map<String, UIInput> components = Collections.synchronizedMap(new HashMap<String, UIInput>());
-
    @Override
    public String getFamily()
    {
@@ -90,12 +83,10 @@
       try
       {
          UIComponent parent = this.getParent();
-         validator.validate(context, parent, components);
+         validator.validate(context, parent, null);
       }
       catch (ValidatorException e)
       {
-         // TODO fire components invalid event
-         setComponentsInvalid();
          setValid(false);
          context.addMessage(null, e.getFacesMessage());
       }
@@ -104,16 +95,22 @@
       context.getApplication().publishEvent(context, PostValidateEvent.class, UIValidateForm.class, this);
    }
 
-   private void setComponentsInvalid()
+   /**
+    * Attempt to locate the form in which this component resides. If the
+    * component is not within a UIForm tag, throw an exception.
+    */
+   public UIForm locateForm()
    {
-      for (UIComponent comp : components.values())
+      UIComponent parent = this.getParent();
+      while (!(parent instanceof UIForm))
       {
-         if ((comp != null) && (comp instanceof UIInput))
+         if ((parent == null) || (parent instanceof UIViewRoot))
          {
-            UIInput input = (UIInput) comp;
-            input.setValid(false);
+            throw new IllegalStateException("The UIValidateForm (<s:validateForm />) component must be placed within a UIForm (<h:form>)");
          }
+         parent = parent.getParent();
       }
+      return (UIForm) parent;
    }
 
    /*
@@ -123,6 +120,7 @@
    @Override
    public void encodeAll(final FacesContext context) throws IOException
    {
+      locateForm();
    }
 
    @Override



More information about the seam-commits mailing list