incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1131093 - in /incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic: extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/ extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/ extval-shared/src/main/java...
Date Fri, 03 Jun 2011 16:21:19 GMT
Author: mbenson
Date: Fri Jun  3 16:21:19 2011
New Revision: 1131093

URL: http://svn.apache.org/viewvc?rev=1131093&view=rev
Log:
special JSF2 handling for AllowedValuesComponentInitializer, do not populate UISelectOne +
UISelectItem unless UISelectItem is no-selection option

Added:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java
  (with props)
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval12/src/main/resources/META-INF/faces-config.xml
      - copied unchanged from r1125096, incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/resources/META-INF/faces-config.xml
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java
  (with props)
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java
  (with props)
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml
  (with props)
Removed:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/resources/
Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java?rev=1131093&r1=1131092&r2=1131093&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
Fri Jun  3 16:21:19 2011
@@ -66,7 +66,15 @@ public class DynamicBeanValidationStartu
         ExtValUtils
             .registerValidationStrategyToMetaDataTransformerNameMapper(new ValuesMetaDataTransformer.Labeled.NameMapper());
 
-        ExtValContext.getContext().addComponentInitializer(new AllowedValuesComponentInitializer());
+        ExtValContext.getContext().addComponentInitializer(createAllowedValuesComponentInitializer());
+    }
+
+    /**
+     * Create the {@link AllowedValuesComponentInitializer} to register.
+     * @return {@link AllowedValuesComponentInitializer}
+     */
+    protected AllowedValuesComponentInitializer createAllowedValuesComponentInitializer()
{
+        return new AllowedValuesComponentInitializer();
     }
 
     private <R extends RendererInterceptor, S extends R> void swap(ExtValContext extValContext,

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer.java?rev=1131093&r1=1131092&r2=1131093&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer.java
Fri Jun  3 16:21:19 2011
@@ -24,6 +24,7 @@ import javax.faces.component.UISelectOne
 import javax.faces.context.FacesContext;
 import javax.faces.model.SelectItem;
 
+import org.apache.bval.jsr303.dynamic.extval.util.ComponentUtils;
 import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
 
 /**
@@ -36,39 +37,22 @@ public class AllowedValuesComponentIniti
     /**
      * {@inheritDoc}
      */
-    public final void configureComponent(FacesContext facesContext, UIComponent uiComponent,
-        Map<String, Object> metaData) {
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData) {
         if (metaData.containsKey(MetaDataKeys.ALLOWED_VALUES) && uiComponent instanceof
UISelectOne) {
-            UISelectItems uiSelectItems = findUISelectItems((UISelectOne) uiComponent);
+            UISelectItems uiSelectItems = ComponentUtils.findFirstChildOfType(UISelectItems.class,
uiComponent);
             if (uiSelectItems != null) {
                 if (!this.isOwner(uiSelectItems)) {
                     return;
                 }
-                uiComponent.getChildren().remove(uiSelectItems);
+            } else {
+                uiSelectItems = createUISelectItems();
+                uiComponent.getChildren().add(uiSelectItems);
             }
-            uiSelectItems = createUISelectItems();
             setValue(uiSelectItems, metaData.get(MetaDataKeys.ALLOWED_VALUES));
-            uiComponent.getChildren().add(uiSelectItems);
         }
     }
 
     /**
-     * Find the first existing {@link UISelectItems} child of a specified parent component.
-     * 
-     * @param parent
-     *            to search
-     * @return {@code UISelectItems} or {@code null}
-     */
-    protected UISelectItems findUISelectItems(UISelectOne parent) {
-        for (UIComponent child : parent.getChildren()) {
-            if (child instanceof UISelectItems) {
-                return (UISelectItems) child;
-            }
-        }
-        return null;
-    }
-
-    /**
      * Generate a {@code UISelectItems} instance, adding our classname as the value of an
attribute mapping keyed by
      * {@code ComponentInitializer}'s classname.
      * 

Added: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java?rev=1131093&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java
(added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java
Fri Jun  3 16:21:19 2011
@@ -0,0 +1,67 @@
+/*
+ *  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.bval.jsr303.dynamic.extval.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * Component utilities.
+ * 
+ * @version $Rev$ $Date$
+ */
+public abstract class ComponentUtils {
+
+    /**
+     * Find the first child of {@code parent} of specified {@code type}.
+     * 
+     * @param <T>
+     * @param type
+     * @param parent
+     * @return child, {@code null} if none found
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends UIComponent> T findFirstChildOfType(Class<T> type,
UIComponent parent) {
+        for (UIComponent child : parent.getChildren()) {
+            if (type.isInstance(child)) {
+                return (T) child;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Find children of {@code parent} of specified {@code type}.
+     * 
+     * @param <T>
+     * @param type
+     * @param parent
+     * @return Iterable
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends UIComponent> Iterable<T> findChildrenOfType(Class<T>
type, UIComponent parent) {
+        ArrayList<T> result = new ArrayList<T>();
+        for (UIComponent child : parent.getChildren()) {
+            if (type.isInstance(child)) {
+                result.add((T) child);
+            }
+        }
+        return result.isEmpty() ? Collections.<T> emptySet() : result;
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/util/ComponentUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java?rev=1131093&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java
(added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java
Fri Jun  3 16:21:19 2011
@@ -0,0 +1,38 @@
+/*
+ *  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.bval.jsr303.dynamic.extval;
+
+import org.apache.bval.jsr303.dynamic.extval.metadata.AllowedValuesComponentInitializer;
+import org.apache.bval.jsr303.dynamic.extval.metadata.AllowedValuesComponentInitializer20;
+
+/**
+ * JSF 2.0-specific {@code DynamicBeanValidationStartupListener}.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DynamicBeanValidationStartupListener20 extends DynamicBeanValidationStartupListener
{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected AllowedValuesComponentInitializer createAllowedValuesComponentInitializer()
{
+        // TODO Auto-generated method stub
+        return new AllowedValuesComponentInitializer20();
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java?rev=1131093&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java
(added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java
Fri Jun  3 16:21:19 2011
@@ -0,0 +1,48 @@
+/*
+ *  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.bval.jsr303.dynamic.extval.metadata;
+
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectItem;
+import javax.faces.context.FacesContext;
+
+import org.apache.bval.jsr303.dynamic.extval.util.ComponentUtils;
+
+/**
+ * Extends {@link AllowedValuesComponentInitializer} to bypass any component which has an
individually specified
+ * {@code UISelectItem} child that is <em>not</em> indicated to be a no-selection
option.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class AllowedValuesComponentInitializer20 extends AllowedValuesComponentInitializer
{
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData) {
+        for (UISelectItem item : ComponentUtils.findChildrenOfType(UISelectItem.class, uiComponent))
{
+            if (item.isNoSelectionOption()) {
+                continue;
+            }
+            return;
+        }
+        super.configureComponent(facesContext, uiComponent, metaData);
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/metadata/AllowedValuesComponentInitializer20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml?rev=1131093&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml
(added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml
Fri Jun  3 16:21:19 2011
@@ -0,0 +1,26 @@
+<!--
+ * 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.
+-->
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
+              version="1.2">
+    <lifecycle>
+        <phase-listener>org.apache.bval.jsr303.dynamic.extval.DynamicBeanValidationStartupListener20</phase-listener>
+    </lifecycle>
+</faces-config>

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/resources/META-INF/faces-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message