[seam-commits] Seam SVN: r11057 - in branches/community/Seam_2_1/src/main/org/jboss/seam: navigation and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun May 31 02:09:29 EDT 2009


Author: dan.j.allen
Date: 2009-05-31 02:09:28 -0400 (Sun, 31 May 2009)
New Revision: 11057

Modified:
   branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Page.java
   branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Pages.java
   branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Param.java
   branches/community/Seam_2_1/src/main/org/jboss/seam/pages-2.1.xsd
Log:
JBSEAM-1587 add validate-model at the <page> level


Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Page.java
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Page.java	2009-05-31 04:15:07 UTC (rev 11056)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Page.java	2009-05-31 06:09:28 UTC (rev 11057)
@@ -34,6 +34,7 @@
    private ValueExpression<String> noConversationViewId;
    private String resourceBundleName;
    private boolean switchEnabled = true;
+   private boolean validateModel = true;
    private List<Param> parameters = new ArrayList<Param>();
    private List<Input> inputs = new ArrayList<Input>();
    private List<Action> actions = new ArrayList<Action>();
@@ -176,6 +177,23 @@
       return switchEnabled;
    }
    
+   public void setValidateModel(boolean validateModel)
+   {
+      this.validateModel = validateModel;
+   }
+   
+   /**
+    * Indicates whether the model validator (Hibernate Validator) should be
+    * registered on the page parameters by default. The default is to add the
+    * model validator. This setting can be overridden per page parameter. If
+    * parameters are registered on the page programatically, this setting should
+    * be honored as the default.
+    */
+   public boolean isValidateModel()
+   {
+      return validateModel;
+   }
+   
    public List<Param> getParameters()
    {
       return parameters;

Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Pages.java	2009-05-31 04:15:07 UTC (rev 11056)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Pages.java	2009-05-31 06:09:28 UTC (rev 11057)
@@ -1124,7 +1124,7 @@
       List<Element> children = element.elements("param");
       for (Element param: children)
       {
-         page.getParameters().add( parseParam(param) );
+         page.getParameters().add( parseParam(param, page.isValidateModel()) );
       }
       
       List<Element> moreChildren = element.elements("navigation");
@@ -1235,6 +1235,13 @@
          }
          page.getInputs().add(input);
       }
+      // by default the model is validated by Hibernate validator; this attribute is used to disable that feature
+      // this setting can be overridden at the param level
+      String validateModelStr = element.attributeValue("validate-model");
+      if (validateModelStr != null)
+      {
+         page.setValidateModel(Boolean.parseBoolean(validateModelStr));
+      }
       
       return page;
    }
@@ -1457,7 +1464,7 @@
    /**
     * Parse param
     */
-   private static Param parseParam(Element element)
+   private static Param parseParam(Element element, boolean validateModel)
    {
       String valueExpression = element.attributeValue("value");
       String name = element.attributeValue("name");
@@ -1469,7 +1476,7 @@
          }
          name = valueExpression.substring(2, valueExpression.length()-1);
       }
-      Param param = new Param(name);
+      Param param = new Param(name, validateModel);
       if (valueExpression!=null)
       {
          param.setValueExpression(Expressions.instance().createValueExpression(valueExpression));
@@ -1559,7 +1566,7 @@
          final List<Param> params = new ArrayList<Param>();
          for (Element child: children)
          {
-            params.add( parseParam(child) );
+            params.add( parseParam(child, true) );
          }
          final String viewId = redirect.attributeValue("view-id");
          final String url    = redirect.attributeValue("url");

Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Param.java
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Param.java	2009-05-31 04:15:07 UTC (rev 11056)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/navigation/Param.java	2009-05-31 06:09:28 UTC (rev 11057)
@@ -35,7 +35,7 @@
    private ValueExpression valueExpression;
    
    private boolean required;
-   private boolean validateModel = true;
+   private boolean validateModel;
    
    private ValueExpression converterValueExpression;
    private String converterId;
@@ -45,7 +45,13 @@
    
    public Param(String name)
    {
+      this(name, true);
+   }
+   
+   public Param(String name, boolean validateModel)
+   {
       this.name = name;
+      this.validateModel = validateModel;
    }
    
    public Converter getConverter()
@@ -186,18 +192,18 @@
 
       String value = parameterValues[0];
       
-      //Note: for not-required fields, we behave a
-      //but different than JSF for empty strings.
-      //is this a bad thing? (but we are the same
-      //for required fields)
-      if ( value.length()==0 && isRequired() )
+      // if the length is zero and the parameter is required, treat the value as
+      // missing (and report it as null); this differs from how JSF handles inputs
+      if (value.length() == 0)
       {
+         if (isRequired())
+         {
          addRequiredMessage(facesContext);
          return null;
       }
+      }
       
       return value;
-      
    }
    
    /**

Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/pages-2.1.xsd
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/pages-2.1.xsd	2009-05-31 04:15:07 UTC (rev 11056)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/pages-2.1.xsd	2009-05-31 06:09:28 UTC (rev 11057)
@@ -124,6 +124,7 @@
         <xs:attribute name="bundle" type="xs:token" />
         <xs:attribute name="conversation" type="xs:token" />
         <xs:attribute name="expires" type="xs:unsignedLong" /> 
+        <xs:attribute name="validate-model" default="true" type="pages:tf-boolean"/>
     </xs:attributeGroup>
     
     <xs:element name="param">




More information about the seam-commits mailing list