myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r938124 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/el/unified/resolver/ test/java/org/apache/myfaces/view/facelets/tag/composite/ test/resources/org/apache/myfaces/view/facelets/tag/composite/ test/resources/org/apache/...
Date Mon, 26 Apr 2010 16:57:08 GMT
Author: jakobk
Date: Mon Apr 26 16:57:08 2010
New Revision: 938124

URL: http://svn.apache.org/viewvc?rev=938124&view=rev
Log:
MYFACES-2675 BeanValidation does not work with composite components (including test case)

Added:
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
  (with props)
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
  (with props)
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
  (with props)
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java?rev=938124&r1=938123&r2=938124&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java
Mon Apr 26 16:57:08 2010
@@ -143,7 +143,7 @@ public final class CompositeComponentELR
             {
                 //create a wrapper map
                 attributesMap = new CompositeComponentAttributesMapWrapper(
-                        baseComponent.getAttributes(), elContext);
+                        baseComponent, elContext);
                 compositeComponentAttributesMaps.put(baseComponent,
                         new WeakReference<Map<String, Object>>(attributesMap));
             }
@@ -152,7 +152,7 @@ public final class CompositeComponentELR
         {
             //Create both required maps
             attributesMap = new CompositeComponentAttributesMapWrapper(
-                    baseComponent.getAttributes(), elContext);
+                    baseComponent, elContext);
             compositeComponentAttributesMaps = new WeakHashMap<UIComponent, WeakReference<Map<String,
Object>>>();
             compositeComponentAttributesMaps.put(baseComponent,
                     new WeakReference<Map<String, Object>>(attributesMap));
@@ -189,14 +189,16 @@ public final class CompositeComponentELR
             Map<String, Object>
     {
 
+        private final UIComponent _component;
         private final BeanInfo _beanInfo;
         private final Map<String, Object> _originalMap;
         private final ELContext _elContext;
         private final PropertyDescriptor [] _propertyDescriptors;
 
-        private CompositeComponentAttributesMapWrapper(Map<String, Object> _originalMap,
ELContext context)
+        private CompositeComponentAttributesMapWrapper(UIComponent component, ELContext context)
         {
-            this._originalMap =_originalMap;
+            this._component = component;
+            this._originalMap = component.getAttributes();
             this._beanInfo = (BeanInfo) _originalMap.get(UIComponent.BEANINFO_KEY);
             this._elContext = context;
             this._propertyDescriptors = _beanInfo.getPropertyDescriptors();
@@ -204,9 +206,7 @@ public final class CompositeComponentELR
 
         public ValueExpression getExpression(String name)
         {
-            Object valueExpr = getAsValueExpression (name);
-
-            // TODO: spec's not clear, I guess this is what we're supposed to do...
+            ValueExpression valueExpr = _component.getValueExpression(name);
 
             return ((valueExpr instanceof ValueExpression) ? (ValueExpression) valueExpr
                     : null);

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java?rev=938124&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
(added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
Mon Apr 26 16:57:08 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.view.facelets.tag.composite;
+
+import java.io.IOException;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.el.CompositeComponentExpressionHolder;
+
+import org.apache.myfaces.el.unified.resolver.CompositeComponentELResolver;
+import org.apache.myfaces.view.facelets.FaceletTestCase;
+
+/**
+ * Tests for using BeanValidation in conjunction with Composite Components.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class CompositeComponentBeanValidationTest extends FaceletTestCase
+{
+
+    /**
+     * Tests the case that a composite component includes an editableValueHolder
+     * attribute which points to a property that is validated via BeanValidation.
+     * In this case the BeanValidator would get the ValueExpression #{cc.attrs.input}
+     * which he does not need. He needs the actual ValueExpression, thus he has
+     * to get it from the composite component. To accomplish this, he uses the
+     * CompositeComponentExpressionHolder interface.
+     * 
+     * @throws IOException
+     */
+    public void testCompositeComponentExpressionHolder() throws IOException
+    {
+        UIViewRoot root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root, "testSimpleEditableValueHolder.xhtml");
+        
+        UIComponent form = root.findComponent("testForm1");
+        UIComponent compositeComponent = form.getChildren().get(0);
+
+        // "resolve" #{cc.attrs}
+        CompositeComponentELResolver resolver = new CompositeComponentELResolver();
+        Object attrs = resolver.getValue(facesContext.getELContext(), compositeComponent,
"attrs");
+        
+        // the resolved value has to be a CompositeComponentExpressionHolder
+        assertTrue(attrs instanceof CompositeComponentExpressionHolder);
+        
+        // get the actual ValueExpression which is needed by the BeanValidator
+        ValueExpression valueExpression 
+                = ((CompositeComponentExpressionHolder) attrs).getExpression("input");
+        
+        // the expression String from the VE has to be #{myBean.input}
+        assertTrue("#{myBean.input}".equals(valueExpression.getExpressionString()));
+    }
+    
+}

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentBeanValidationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml?rev=938124&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
(added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
Mon Apr 26 16:57:08 2010
@@ -0,0 +1,31 @@
+<!--
+ Licensed 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.
+
+ $Id$
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:composite="http://java.sun.com/jsf/composite">
+<head>
+</head>
+<body>
+<composite:interface>
+    <composite:editableValueHolder name="input" />
+</composite:interface>
+<composite:implementation>
+    <h:inputText id="input" value="#{cc.attrs.input}" />
+</composite:implementation>
+</body>
+</html>

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleEditableValueHolder.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml?rev=938124&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
(added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
Mon Apr 26 16:57:08 2010
@@ -0,0 +1,28 @@
+<!--
+ Licensed 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.
+
+ $Id$
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:testComposite="http://java.sun.com/jsf/composite/testComposite">
+<head>
+</head>
+<body>
+    <h:form id="testForm1">
+        <testComposite:simpleEditableValueHolder input="#{myBean.input}" />
+    </h:form>
+</body>
+</html>

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleEditableValueHolder.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message