myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r826802 - in /myfaces/extensions/validator/trunk: component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/ core/src/main/java/org/apache/myfaces/extensions/validator/core/initi...
Date Mon, 19 Oct 2009 20:49:01 GMT
Author: gpetracek
Date: Mon Oct 19 20:49:00 2009
New Revision: 826802

URL: http://svn.apache.org/viewvc?rev=826802&view=rev
Log:
EXTVAL-68 minor changes

Added:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/AbstractHtmlCoreComponentsComponentInitializer.java
Modified:
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/RequiredInitializer.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/HtmlCoreComponentsComponentInitializer.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/RequiredInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/RequiredInitializer.java?rev=826802&r1=826801&r2=826802&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/RequiredInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/initializer/component/RequiredInitializer.java
Mon Oct 19 20:49:00 2009
@@ -20,6 +20,7 @@
 
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.trinidad.util.TrinidadUtils;
@@ -41,6 +42,11 @@
     public boolean configureTrinidadComponent(FacesContext facesContext, UIComponent uiComponent,
                                               Map<String, Object> metaData)
     {
+        if(!validateEmptyFields())
+        {
+            return false;
+        }
+
         if(metaData.containsKey(CommonMetaDataKeys.REQUIRED) ||
            metaData.containsKey(CommonMetaDataKeys.WEAK_REQUIRED)||
            metaData.containsKey(CommonMetaDataKeys.SKIP_VALIDATION))
@@ -80,6 +86,11 @@
         return false;
     }
 
+    protected boolean validateEmptyFields()
+    {
+        return ExtValUtils.validateEmptyFields();
+    }
+
     protected Boolean isComponentRequired(UIComponent uiComponent)
     {
         if(uiComponent instanceof CoreOutputLabel)

Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/AbstractHtmlCoreComponentsComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/AbstractHtmlCoreComponentsComponentInitializer.java?rev=826802&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/AbstractHtmlCoreComponentsComponentInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/AbstractHtmlCoreComponentsComponentInitializer.java
Mon Oct 19 20:49:00 2009
@@ -0,0 +1,120 @@
+/*
+ * 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.extensions.validator.core.initializer.component;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlInputSecret;
+import javax.faces.component.html.HtmlSelectBooleanCheckbox;
+import javax.faces.component.html.HtmlSelectOneListbox;
+import javax.faces.component.html.HtmlSelectOneMenu;
+import javax.faces.component.html.HtmlSelectOneRadio;
+import javax.faces.component.html.HtmlSelectManyCheckbox;
+import javax.faces.component.html.HtmlSelectManyListbox;
+import javax.faces.component.html.HtmlSelectManyMenu;
+import javax.faces.component.html.HtmlInputTextarea;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.REUSE)
+public abstract class AbstractHtmlCoreComponentsComponentInitializer implements ComponentInitializer
+{
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
+    {
+        if(processComponent(uiComponent))
+        {
+            if(validateEmptyFields())
+            {
+                configureRequiredAttribute(facesContext, uiComponent, metaData);
+            }
+
+            configureMaxLengthAttribute(facesContext, uiComponent, metaData);
+        }
+    }
+
+    protected boolean validateEmptyFields()
+    {
+        return ExtValUtils.validateEmptyFields();
+    }
+
+    protected abstract void configureRequiredAttribute(FacesContext facesContext,
+                                              UIComponent uiComponent,
+                                              Map<String, Object> metaData);
+
+    protected boolean processComponent(UIComponent uiComponent)
+    {
+        return uiComponent instanceof HtmlInputText ||
+                uiComponent instanceof HtmlInputSecret ||
+                uiComponent instanceof HtmlSelectBooleanCheckbox ||
+                uiComponent instanceof HtmlSelectOneListbox ||
+                uiComponent instanceof HtmlSelectOneMenu ||
+                uiComponent instanceof HtmlSelectOneRadio ||
+                uiComponent instanceof HtmlSelectManyCheckbox ||
+                uiComponent instanceof HtmlSelectManyListbox ||
+                uiComponent instanceof HtmlSelectManyMenu ||
+                uiComponent instanceof HtmlInputTextarea;
+    }
+
+    /**
+     * if there is no special attribute at the component which should overrule
+     * the annotated property return true!
+     *
+     * @param uiComponent component which implements the EditableValueHolder interface
+     * @return false to overrule the annotated property e.g. if component is readonly
+     */
+    protected Boolean isComponentRequired(UIComponent uiComponent)
+    {
+        boolean isReadOnly = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
+                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isReadonly")));
+        boolean isDisabled = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
+                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isDisabled")));
+
+        return !(isReadOnly || isDisabled);
+    }
+
+    protected void configureMaxLengthAttribute(FacesContext facesContext,
+                                             UIComponent uiComponent,
+                                             Map<String, Object> metaData)
+    {
+        if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH))
+        {
+            Object maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH);
+
+            if(!(maxLength instanceof Integer))
+            {
+                return;
+            }
+            if(uiComponent instanceof HtmlInputText)
+            {
+                HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
+                htmlInputText.setMaxlength((Integer)maxLength);
+            }
+        }
+    }
+}

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java?rev=826802&r1=826801&r2=826802&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
Mon Oct 19 20:49:00 2009
@@ -144,8 +144,7 @@
 
     protected boolean validateEmptyFields()
     {
-        //to deactivate: the parameter has to be explicitly false
-        return !"false".equalsIgnoreCase(WebXmlParameter.VALIDATE_EMPTY_FIELDS);
+        return ExtValUtils.validateEmptyFields();
     }
 
     protected boolean interpretEmptyStringValuesAsNull()

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=826802&r1=826801&r2=826802&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
Mon Oct 19 20:49:00 2009
@@ -641,4 +641,9 @@
     {
         return propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS,
PropertyDetails.class);
     }
+
+    public static boolean validateEmptyFields()
+    {
+        return !"false".equalsIgnoreCase(WebXmlParameter.VALIDATE_EMPTY_FIELDS);
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/HtmlCoreComponentsComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/HtmlCoreComponentsComponentInitializer.java?rev=826802&r1=826801&r2=826802&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/HtmlCoreComponentsComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/HtmlCoreComponentsComponentInitializer.java
Mon Oct 19 20:49:00 2009
@@ -18,48 +18,27 @@
  */
 package org.apache.myfaces.extensions.validator.beanval;
 
-import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.component
+        .AbstractHtmlCoreComponentsComponentInitializer;
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.core.InvocationOrder;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
-import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
-import javax.faces.component.html.HtmlInputText;
-import javax.faces.component.html.HtmlInputSecret;
-import javax.faces.component.html.HtmlSelectBooleanCheckbox;
-import javax.faces.component.html.HtmlSelectOneListbox;
-import javax.faces.component.html.HtmlSelectOneMenu;
-import javax.faces.component.html.HtmlSelectOneRadio;
-import javax.faces.component.html.HtmlSelectManyCheckbox;
-import javax.faces.component.html.HtmlSelectManyListbox;
-import javax.faces.component.html.HtmlSelectManyMenu;
-import javax.faces.component.html.HtmlInputTextarea;
 import javax.faces.context.FacesContext;
 import java.util.Map;
 
 /**
- * keep in sync with: org.apache.myfaces.extensions.validator.HtmlCoreComponentsComponentInitializer
- *
  * @author Gerhard Petracek
  * @since x.x.3
  */
 @InvocationOrder(200)
 @UsageInformation(UsageCategory.INTERNAL)
-public class HtmlCoreComponentsComponentInitializer implements ComponentInitializer
+public class HtmlCoreComponentsComponentInitializer extends AbstractHtmlCoreComponentsComponentInitializer
 {
-    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
-    {
-        if(processComponent(uiComponent))
-        {
-            configureRequiredAttribute(facesContext, uiComponent, metaData);
-            configureMaxLengthAttribute(facesContext, uiComponent, metaData);
-        }
-    }
-
     protected void configureRequiredAttribute(FacesContext facesContext,
                                               UIComponent uiComponent,
                                               Map<String, Object> metaData)
@@ -79,55 +58,4 @@
             ((EditableValueHolder)uiComponent).setRequired(false);
         }
     }
-
-    protected boolean processComponent(UIComponent uiComponent)
-    {
-        return uiComponent instanceof HtmlInputText ||
-                uiComponent instanceof HtmlInputSecret ||
-                uiComponent instanceof HtmlSelectBooleanCheckbox ||
-                uiComponent instanceof HtmlSelectOneListbox ||
-                uiComponent instanceof HtmlSelectOneMenu ||
-                uiComponent instanceof HtmlSelectOneRadio ||
-                uiComponent instanceof HtmlSelectManyCheckbox ||
-                uiComponent instanceof HtmlSelectManyListbox ||
-                uiComponent instanceof HtmlSelectManyMenu ||
-                uiComponent instanceof HtmlInputTextarea;
-    }
-
-    /**
-     * if there is no special attribute at the component which should overrule
-     * the annotated property return true!
-     *
-     * @param uiComponent component which implements the EditableValueHolder interface
-     * @return false to overrule the annotated property e.g. if component is readonly
-     */
-    protected Boolean isComponentRequired(UIComponent uiComponent)
-    {
-        boolean isReadOnly = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
-                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isReadonly")));
-        boolean isDisabled = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
-                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isDisabled")));
-
-        return !(isReadOnly || isDisabled);
-    }
-
-    protected void configureMaxLengthAttribute(FacesContext facesContext,
-                                             UIComponent uiComponent,
-                                             Map<String, Object> metaData)
-    {
-        if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH))
-        {
-            Object maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH);
-
-            if(!(maxLength instanceof Integer))
-            {
-                return;
-            }
-            if(uiComponent instanceof HtmlInputText)
-            {
-                HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
-                htmlInputText.setMaxlength((Integer)maxLength);
-            }
-        }
-    }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java?rev=826802&r1=826801&r2=826802&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
Mon Oct 19 20:49:00 2009
@@ -18,25 +18,15 @@
  */
 package org.apache.myfaces.extensions.validator;
 
-import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.component
+        .AbstractHtmlCoreComponentsComponentInitializer;
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.core.InvocationOrder;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
-import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
-import javax.faces.component.html.HtmlInputText;
-import javax.faces.component.html.HtmlInputSecret;
-import javax.faces.component.html.HtmlSelectBooleanCheckbox;
-import javax.faces.component.html.HtmlSelectOneListbox;
-import javax.faces.component.html.HtmlSelectOneMenu;
-import javax.faces.component.html.HtmlSelectOneRadio;
-import javax.faces.component.html.HtmlSelectManyCheckbox;
-import javax.faces.component.html.HtmlSelectManyListbox;
-import javax.faces.component.html.HtmlSelectManyMenu;
-import javax.faces.component.html.HtmlInputTextarea;
 import javax.faces.context.FacesContext;
 import java.util.Map;
 
@@ -46,23 +36,12 @@
  */
 @InvocationOrder(200)
 @UsageInformation(UsageCategory.INTERNAL)
-public class HtmlCoreComponentsComponentInitializer implements ComponentInitializer
+public class HtmlCoreComponentsComponentInitializer extends AbstractHtmlCoreComponentsComponentInitializer
 {
-    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
-    {
-        configureRequiredAttribute(facesContext, uiComponent, metaData);
-        configureMaxLengthAttribute(facesContext, uiComponent, metaData);
-    }
-
     protected void configureRequiredAttribute(FacesContext facesContext,
                                               UIComponent uiComponent,
                                               Map<String, Object> metaData)
     {
-        if(!processComponent(uiComponent))
-        {
-            return;
-        }
-
         if((Boolean.TRUE.equals(metaData.get(CommonMetaDataKeys.WEAK_REQUIRED)) ||
              Boolean.TRUE.equals(metaData.get(CommonMetaDataKeys.REQUIRED)))
             &&
@@ -76,55 +55,4 @@
             ((EditableValueHolder)uiComponent).setRequired(false);
         }
     }
-
-    protected boolean processComponent(UIComponent uiComponent)
-    {
-        return uiComponent instanceof HtmlInputText ||
-                uiComponent instanceof HtmlInputSecret ||
-                uiComponent instanceof HtmlSelectBooleanCheckbox ||
-                uiComponent instanceof HtmlSelectOneListbox ||
-                uiComponent instanceof HtmlSelectOneMenu ||
-                uiComponent instanceof HtmlSelectOneRadio ||
-                uiComponent instanceof HtmlSelectManyCheckbox ||
-                uiComponent instanceof HtmlSelectManyListbox ||
-                uiComponent instanceof HtmlSelectManyMenu ||
-                uiComponent instanceof HtmlInputTextarea;
-    }
-
-    /**
-     * if there is no special attribute at the component which should overrule
-     * the annotated property return true!
-     *
-     * @param uiComponent component which implements the EditableValueHolder interface
-     * @return false to overrule the annotated property e.g. if component is readonly
-     */
-    protected Boolean isComponentRequired(UIComponent uiComponent)
-    {
-        boolean isReadOnly = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
-                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isReadonly")));
-        boolean isDisabled = !Boolean.FALSE.equals(ReflectionUtils.tryToInvokeMethod(
-                uiComponent, ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "isDisabled")));
-
-        return !(isReadOnly || isDisabled);
-    }
-
-    protected void configureMaxLengthAttribute(FacesContext facesContext,
-                                             UIComponent uiComponent,
-                                             Map<String, Object> metaData)
-    {
-        if(metaData.containsKey(CommonMetaDataKeys.MAX_LENGTH))
-        {
-            Object maxLength = metaData.get(CommonMetaDataKeys.MAX_LENGTH);
-
-            if(!(maxLength instanceof Integer))
-            {
-                return;
-            }
-            if(uiComponent instanceof HtmlInputText)
-            {
-                HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
-                htmlInputText.setMaxlength((Integer)maxLength);
-            }
-        }
-    }
 }



Mime
View raw message