You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2012/09/10 12:51:43 UTC

svn commit: r1382752 - in /myfaces/tobago/trunk: tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ tobago-example/tobago-example-test/src/main/resources/META-INF/ tobago-example/tobago-example-test/src/main/webapp...

Author: lofwyr
Date: Mon Sep 10 10:51:42 2012
New Revision: 1382752

URL: http://svn.apache.org/viewvc?rev=1382752&view=rev
Log:
TOBAGO-1194: The component tc:attribute with mode="valueIsSet" doesn't work for facelet tags, some cases.
 fixing case 2: string literal for boolean: e.g. modal="false"

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/PopupModalAttribute.java
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/popup.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/tobago-example-test.taglib.xml
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.selenium.html
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.xhtml
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/tobago-extension/tobago-facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/PopupModalAttribute.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/PopupModalAttribute.java?rev=1382752&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/PopupModalAttribute.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/PopupModalAttribute.java Mon Sep 10 10:51:42 2012
@@ -0,0 +1,31 @@
+/*
+ * 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.tobago.example.test;
+
+public class PopupModalAttribute {
+
+  public boolean isAlwaysTrue() {
+    return true;
+  }
+
+  public boolean isAlwaysFalse() {
+    return false;
+  }
+}

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/popup.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/popup.xhtml?rev=1382752&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/popup.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/popup.xhtml Mon Sep 10 10:51:42 2012
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+
+<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:f="http://java.sun.com/jsf/core">
+
+  <tc:button label="#{label}">
+    <f:facet name="popup">
+      <tc:popup>
+        <tc:attribute name="modal" value="#{modal}" mode="valueIfSet"/>
+        <f:facet name="layout">
+          <tc:gridLayout rows="auto" columns="200px"/>
+        </f:facet>
+        <tc:box label="#{label}">
+          <tc:button label="Close">
+            <tc:attribute name="popupClose" value="immediate"/>
+          </tc:button>
+            </tc:box>
+      </tc:popup>
+    </f:facet>
+  </tc:button>
+</ui:composition>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/tobago-example-test.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/tobago-example-test.taglib.xml?rev=1382752&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/tobago-example-test.taglib.xml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/resources/META-INF/tobago-example-test.taglib.xml Mon Sep 10 10:51:42 2012
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+    "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+    "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+<facelet-taglib>
+  <namespace>http://myfaces.apache.org/tobago/example/test</namespace>
+  <tag>
+    <tag-name>popup</tag-name>
+    <source>popup.xhtml</source>
+  </tag>
+</facelet-taglib>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml?rev=1382752&r1=1382751&r2=1382752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml Mon Sep 10 10:51:42 2012
@@ -150,6 +150,12 @@
   </managed-bean>
 
   <managed-bean>
+    <managed-bean-name>popupModalAttribute</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.test.PopupModalAttribute</managed-bean-class>
+    <managed-bean-scope>none</managed-bean-scope>
+  </managed-bean>
+
+  <managed-bean>
     <managed-bean-name>progress</managed-bean-name>
     <managed-bean-class>org.apache.myfaces.tobago.example.test.Progress</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.selenium.html
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.selenium.html?rev=1382752&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.selenium.html (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.selenium.html Mon Sep 10 10:51:42 2012
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ * 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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8080/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+	<td>open</td>
+	<td>/faces/test/attribute/popup-modal.xhtml</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[1]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup tobago-popup-markup-modal</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[2]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup tobago-popup-markup-modal</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[3]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[4]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup tobago-popup-markup-modal</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[5]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[6]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup tobago-popup-markup-modal</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>//button[7]</td>
+	<td></td>
+</tr>
+<tr>
+	<td>waitForElementPresent</td>
+	<td>class=tobago-popup</td>
+	<td></td>
+</tr>
+<tr>
+	<td>click</td>
+	<td>//div[2]/button</td>
+	<td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.xhtml?rev=1382752&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/attribute/popup-modal.xhtml Mon Sep 10 10:51:42 2012
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+
+<f:view
+    xmlns:tc="http://myfaces.apache.org/tobago/component"
+    xmlns:test="http://myfaces.apache.org/tobago/example/test"
+    xmlns:f="http://java.sun.com/jsf/core">
+
+  <tc:page>
+
+    <f:facet name="layout">
+      <tc:gridLayout columns="300px" rows="auto;auto;auto;auto;auto;auto;auto"/>
+    </f:facet>
+
+    <test:popup id="d" label="modal: default"/>
+    <test:popup id="t" label="modal: true" modal="true"/>
+    <test:popup id="f" label="modal: false" modal="false"/>
+    <test:popup id="te" label="modal: \#{true}" modal="#{true}"/>
+    <test:popup id="fe" label="modal: \#{false}" modal="#{false}"/>
+    <test:popup id="tb" label="modal: \#{popupModalAttribute.alwaysTrue}" modal="#{popupModalAttribute.alwaysTrue}"/>
+    <test:popup id="fb" label="modal: \#{popupModalAttribute.alwaysFalse}" modal="#{popupModalAttribute.alwaysFalse}"/>
+
+  </tc:page>
+</f:view>

Modified: myfaces/tobago/trunk/tobago-extension/tobago-facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-extension/tobago-facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java?rev=1382752&r1=1382751&r2=1382752&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-extension/tobago-facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java (original)
+++ myfaces/tobago/trunk/tobago-extension/tobago-facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java Mon Sep 10 10:51:42 2012
@@ -28,6 +28,7 @@ import com.sun.facelets.tag.TagConfig;
 import com.sun.facelets.tag.TagException;
 import com.sun.facelets.tag.TagHandler;
 import com.sun.facelets.tag.jsf.ComponentSupport;
+import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.SupportsMarkup;
@@ -48,6 +49,8 @@ import javax.faces.component.EditableVal
 import javax.faces.component.UIComponent;
 import javax.faces.component.ValueHolder;
 import javax.faces.convert.Converter;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
 
 public final class AttributeHandler extends TagHandler {
 
@@ -198,11 +201,13 @@ public final class AttributeHandler exte
             }
           }
           if (expressionString != null) {
+            final String attributeName = name.getValue(faceletContext);
             if (containsMethodOrValueExpression(expressionString)) {
               ValueExpression expression = value.getValueExpression(faceletContext, Object.class);
-              ELAdaptor.setExpression(parent, name.getValue(faceletContext), expression);
+              ELAdaptor.setExpression(parent, attributeName, expression);
             } else {
-              parent.getAttributes().put(name.getValue(faceletContext), expressionString);
+              final Object literalValue = getValue(faceletContext, parent, expressionString, attributeName);
+              parent.getAttributes().put(attributeName, literalValue);
             }
           }
         } else {
@@ -319,6 +324,21 @@ public final class AttributeHandler exte
     }
   }
 
+  private Object getValue(
+      FaceletContext faceletContext, UIComponent parent, String expressionString, String attributeName) {
+    Class type = Object.class;
+    try {
+      type = PropertyUtils.getReadMethod(
+          new PropertyDescriptor(attributeName, parent.getClass())).getReturnType();
+    } catch (IntrospectionException e) {
+      LOG.warn("Can't determine expected type", e);
+    }
+    ExpressionFactory expressionFactory = faceletContext.getExpressionFactory();
+    final ValueExpression valueExpression = expressionFactory
+        .createValueExpression(faceletContext, expressionString, type);
+    return valueExpression.getValue(faceletContext);
+  }
+
   private void setConverter(FaceletContext faceletContext, UIComponent parent, String nameValue) {
     // in a composition may be we get the converter expression string from the current variable mapper
     // the expression can be empty