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 2011/03/17 15:28:39 UTC
svn commit: r1082502 - in /myfaces/tobago/branches/tobago-1.0.x:
example/test/src/main/java/org/apache/myfaces/tobago/example/test/
example/test/src/main/webapp/WEB-INF/
example/test/src/main/webapp/tc/attribute/
extension/facelets/src/main/java/org/ap...
Author: lofwyr
Date: Thu Mar 17 14:28:39 2011
New Revision: 1082502
URL: http://svn.apache.org/viewvc?rev=1082502&view=rev
Log:
TOBAGO-980: tc:attribute mode="valueIfSet" not working in some cases
Added:
myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Attribute.java
myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/
myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/mode-valueIfSet.xhtml
Modified:
myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/WEB-INF/faces-config.xml
myfaces/tobago/branches/tobago-1.0.x/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
Added: myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Attribute.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Attribute.java?rev=1082502&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Attribute.java (added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Attribute.java Thu Mar 17 14:28:39 2011
@@ -0,0 +1,25 @@
+package org.apache.myfaces.tobago.example.test;
+
+/*
+ * 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.
+ */
+
+public class Attribute {
+
+ public String getValue() {
+ return "value from model";
+ }
+}
Modified: myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/WEB-INF/faces-config.xml?rev=1082502&r1=1082501&r2=1082502&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/WEB-INF/faces-config.xml Thu Mar 17 14:28:39 2011
@@ -53,6 +53,12 @@
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>attribute</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.tobago.example.test.Attribute</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+
<lifecycle>
<phase-listener>
org.apache.myfaces.tobago.example.test.DebugModePhaseListener
Added: myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/mode-valueIfSet.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/mode-valueIfSet.xhtml?rev=1082502&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/mode-valueIfSet.xhtml (added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/attribute/mode-valueIfSet.xhtml Thu Mar 17 14:28:39 2011
@@ -0,0 +1,104 @@
+<?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:tx="http://myfaces.apache.org/tobago/extension"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:c="http://java.sun.com/jstl/core">
+
+ <tc:page id="page" width="600px" height="350px">
+ <f:facet name="layout">
+ <tc:gridLayout rows="fixed;7*;5*"/>
+ </f:facet>
+
+ <tc:label value="demo of the valueIfSet mode of tc:attribute (facelets only)"/>
+
+ <tc:box label="value">
+ <f:facet name="layout">
+ <tc:gridLayout rows="auto;auto;auto;auto;auto;auto;*" columns="250px;*"/>
+ </f:facet>
+
+ <tc:label value="value"/>
+ <tc:in>
+ <tc:attribute name="value" value="direct literal" mode="valueIfSet"/>
+ </tc:in>
+
+ <c:set var="value1" value="from var"/>
+ <tc:label value="value"/>
+ <tc:in>
+ <tc:attribute name="value" value="#{value1}" mode="valueIfSet"/>
+ </tc:in>
+
+ <c:set var="value2" value="#{value1}"/>
+ <tc:label value="value"/>
+ <tc:in>
+ <tc:attribute name="value" value="#{value2}" mode="valueIfSet"/>
+ </tc:in>
+
+ <c:set var="value3" value="#{value1} ++"/>
+ <tc:label value="value"/>
+ <tc:in>
+ <tc:attribute name="value" value="#{value3}" mode="valueIfSet"/>
+ </tc:in>
+
+ <c:set var="value4" value="#{attribute.value}"/>
+ <tc:label value="value"/>
+ <tc:in>
+ <tc:attribute name="value" value="#{value4}" mode="valueIfSet"/>
+ </tc:in>
+
+ <tc:label value="value (undefined)"/>
+ <tc:in>
+ <tc:attribute name="value" value="#{value_undefined}" mode="valueIfSet"/>
+ </tc:in>
+
+ </tc:box>
+
+ <tc:box label="id (you may see the ids in the DOM)" id="id-box">
+ <f:facet name="layout">
+ <tc:gridLayout rows="auto;auto;auto;auto;auto;auto;*" columns="250px;*"/>
+ </f:facet>
+
+ <tc:label value="id"/>
+ <tc:in>
+ <tc:attribute name="id" value="my_number_1" mode="valueIfSet"/>
+ </tc:in>
+
+ <tc:label value="id (not implemented)"/>
+ <tc:in>
+ <tc:attribute name="id" value="#{'my_number_2'}" mode="valueIfSet"/>
+ </tc:in>
+
+ <c:set var="id3" value="my_number_3"/>
+ <tc:label value="id"/>
+ <tc:in>
+ <tc:attribute name="id" value="#{id3}" mode="valueIfSet"/>
+ </tc:in>
+
+ <tc:label value="id (undefined)"/>
+ <tc:in>
+ <tc:attribute name="id" value="#{id_undefined}" mode="valueIfSet"/>
+ </tc:in>
+
+ </tc:box>
+
+ </tc:page>
+</f:view>
Modified: myfaces/tobago/branches/tobago-1.0.x/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java?rev=1082502&r1=1082501&r2=1082502&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java Thu Mar 17 14:28:39 2011
@@ -181,13 +181,12 @@ public final class AttributeHandler exte
}
} else if ("valueIfSet".equals(mode.getValue())) {
String expressionString = value.getValue();
- while (isSimpleExpression(expressionString)) {
- if (isMethodOrValueExpression(expressionString)) {
+ while (isMethodOrValueExpression(expressionString) && isSimpleExpression(expressionString)) {
ValueExpression expression
= faceletContext.getVariableMapper().resolveVariable(removeElParenthesis(expressionString));
if (expression == null) {
if (LOG.isDebugEnabled()) {
- // when the action hasn't been set while using a componsition.
+ // when the action hasn't been set while using a composition.
LOG.debug("Variable can't be resolved: value='" + expressionString + "'");
}
expressionString = null;
@@ -195,15 +194,14 @@ public final class AttributeHandler exte
} else {
expressionString = expression.getExpressionString();
}
- } else {
- LOG.warn("Only expressions are supported mode=valueIfSet value='" + expressionString + "'");
- expressionString = null;
- break;
}
- }
if (expressionString != null) {
+ if (containsMethodOrValueExpression(expressionString)) {
ValueExpression expression = value.getValueExpression(faceletContext, Object.class);
ELAdaptor.setExpression(parent, name.getValue(faceletContext), expression);
+ } else {
+ parent.getAttributes().put(name.getValue(faceletContext), expressionString);
+ }
}
} else {
throw new FacesException("Type " + mode + " not suppored");
@@ -280,6 +278,11 @@ public final class AttributeHandler exte
return (string.startsWith("${") || string.startsWith("#{")) && string.endsWith("}");
}
+ private boolean containsMethodOrValueExpression(String string) {
+ return (StringUtils.contains(string, "${") || StringUtils.contains(string, "#{"))
+ && StringUtils.contains(string, "}");
+ }
+
private boolean isSimpleExpression(String string) {
return string.indexOf('.') < 0 && string.indexOf('[') < 0;
}