You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/03/29 20:53:31 UTC

svn commit: r928864 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/tag/composite/ test/java/org/apache/myfaces/view/facelets/tag/composite/ test/resources/org/apache/myfaces/view/facelets/tag/composite/ test/resources/org...

Author: lu4242
Date: Mon Mar 29 18:53:31 2010
New Revision: 928864

URL: http://svn.apache.org/viewvc?rev=928864&view=rev
Log:
MYFACES-2633 Cannot set properties on custom composite component class when are implemented on getter/setter

Added:
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentAttributeTestCase.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeTestComponent.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/TestAttributeBean.java
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeVE.xhtml
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleAttributeVE.xhtml
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentRule.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentRule.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentRule.java?rev=928864&r1=928863&r2=928864&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentRule.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentRule.java Mon Mar 29 18:53:31 2010
@@ -80,8 +80,8 @@ final class CompositeComponentRule exten
             // prevents it and does not cause any side effects.
             // Maybe we should call setValueExpression when the getter and 
             // setter exists on the component class.
-            ((UIComponent) instance).getAttributes().put(_name, _attr.getValueExpression(ctx, _type));
-            //((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type));
+            //((UIComponent) instance).getAttributes().put(_name, _attr.getValueExpression(ctx, _type));
+            ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type));
             //((UIComponent) instance).setValueExpression(_name, 
             //        ctx.getFacesContext().getApplication().
             //        getExpressionFactory().createValueExpression(

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentAttributeTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentAttributeTestCase.java?rev=928864&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentAttributeTestCase.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentAttributeTestCase.java Mon Mar 29 18:53:31 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.StringWriter;
+
+import javax.el.MethodExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlCommandButton;
+import javax.faces.component.html.HtmlOutputText;
+
+import org.apache.myfaces.test.mock.MockResponseWriter;
+import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
+import org.apache.myfaces.test.utils.HtmlRenderedAttr;
+import org.apache.myfaces.view.facelets.FaceletTestCase;
+
+public class CompositeComponentAttributeTestCase extends FaceletTestCase
+{
+
+    @Override
+    protected void setupComponents() throws Exception
+    {
+        super.setupComponents();
+        application.addComponent(CompositeTestComponent.class.getName(), 
+                CompositeTestComponent.class.getName());
+    }
+
+    /**
+     * Test simple attribute resolution (not set, default, normal use case).
+     * 
+     * @throws Exception
+     */
+    public void testSimpleCompositeAttribute() throws Exception
+    {
+        TestAttributeBean bean = new TestAttributeBean();
+        
+        facesContext.getExternalContext().getRequestMap().put("bean",
+                bean);
+        
+        UIViewRoot root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root, "testSimpleAttributeVE.xhtml");
+
+        UIComponent panelGroup1 = root.findComponent("testGroup1");
+        assertNotNull(panelGroup1);
+        CompositeTestComponent compositeComponent1 = (CompositeTestComponent) panelGroup1.getChildren().get(0);
+        assertNotNull(compositeComponent1);
+        UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+        assertNotNull(facet1);
+        HtmlOutputText text1 = (HtmlOutputText) facet1.findComponent("text");
+        assertNotNull(text1);
+        HtmlCommandButton button1 = (HtmlCommandButton) facet1.findComponent("button");
+        assertNotNull(button1);
+        
+        compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
+        facet1.pushComponentToEL(facesContext, facet1);
+        text1.pushComponentToEL(facesContext, text1);
+        //set on tag
+        assertEquals(bean.getStyleClass(), text1.getStyleClass());
+        //set as default
+        assertEquals(bean.getStyle(), text1.getStyle());
+        text1.popComponentFromEL(facesContext);
+        button1.pushComponentToEL(facesContext,  button1);
+        MethodExpression method = button1.getActionExpression();
+        assertEquals(bean.doSomethingFunny("xysj"), method.invoke(facesContext.getELContext(), new Object[]{"xysj"}));
+        button1.popComponentFromEL(facesContext);
+        facet1.popComponentFromEL(facesContext);
+        compositeComponent1.popComponentFromEL(facesContext);
+        
+        StringWriter sw = new StringWriter();
+        MockResponseWriter mrw = new MockResponseWriter(sw);
+        facesContext.setResponseWriter(mrw);
+        
+        compositeComponent1.encodeAll(facesContext);
+        sw.flush();
+        
+        HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[]{
+                new HtmlRenderedAttr("style")
+        };
+            
+        HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
+    }
+}

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeTestComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeTestComponent.java?rev=928864&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeTestComponent.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeTestComponent.java Mon Mar 29 18:53:31 2010
@@ -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.
+ */
+package org.apache.myfaces.view.facelets.tag.composite;
+
+import javax.faces.component.UINamingContainer;
+
+public class CompositeTestComponent extends UINamingContainer
+{
+
+}

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/TestAttributeBean.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/TestAttributeBean.java?rev=928864&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/TestAttributeBean.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/TestAttributeBean.java Mon Mar 29 18:53:31 2010
@@ -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.myfaces.view.facelets.tag.composite;
+
+public class TestAttributeBean
+{
+
+    public String getStyle()
+    {
+        return "style1";
+    }
+    
+    public String getStyleClass()
+    {
+        return "styleclass1";
+    }
+    
+    public String doSomethingFunny(String a)
+    {
+        return "somethingFunny"+a;
+    }
+}

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeVE.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeVE.xhtml?rev=928864&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeVE.xhtml (added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeVE.xhtml Mon Mar 29 18:53:31 2010
@@ -0,0 +1,34 @@
+<!--
+ 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: defineInclude.xml 804043 2009-08-13 22:08:44Z lu4242 $
+-->
+<!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 componentType="org.apache.myfaces.view.facelets.tag.composite.CompositeTestComponent">
+    <composite:attribute name="style" default="background:red"/>
+    <composite:attribute name="styleClass" />
+    <composite:attribute name="customMethod" method-signature="String doSomething(String)"/>
+</composite:interface>
+<composite:implementation>
+    <h:outputText id="text" value="Hello World" style="#{cc.attrs.style}" styleClass="#{cc.attrs.styleClass}"/>
+    <h:commandButton id="button" action="#{cc.attrs.customMethod}"/>
+</composite:implementation>
+</body>
+</html>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleAttributeVE.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleAttributeVE.xhtml?rev=928864&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleAttributeVE.xhtml (added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleAttributeVE.xhtml Mon Mar 29 18:53:31 2010
@@ -0,0 +1,29 @@
+<!--
+ 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: defineInclude.xml 804043 2009-08-13 22:08:44Z lu4242 $
+-->
+<!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:panelGroup id="testGroup1">
+<testComposite:simpleAttributeVE style="#{bean.style}" styleClass="#{bean.styleClass}" customMethod="#{bean.doSomethingFunny}">
+</testComposite:simpleAttributeVE>
+</h:panelGroup>
+</body>
+</html>
\ No newline at end of file