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 2016/05/19 23:39:41 UTC
svn commit: r1744645 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/view/facelets/compiler/
test/java/org/apache/myfaces/view/facelets/pss/acid/
test/java/org/apache/myfaces/view/facelets/pss/acid/component/
test/java/org/apache/myface...
Author: lu4242
Date: Thu May 19 23:39:41 2016
New Revision: 1744645
URL: http://svn.apache.org/viewvc?rev=1744645&view=rev
Log:
MYFACES-4046 Allow programmatic component with ui:include with ui:param
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleIncludeVDL2.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/TestBean.java
myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleIncludeVDL_2_1.xhtml
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java?rev=1744645&r1=1744644&r2=1744645&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java Thu May 19 23:39:41 2016
@@ -897,29 +897,72 @@ public final class SAXCompiler extends C
String prefix = "oamf"; // The prefix is only a logical name.
mngr.pushNamespace(prefix, taglibURI);
+ boolean tagContainParams = (
+ ("include".equals(tagName) || "decorate".equals(tagName) || "composition".equals(tagName)) &&
+ (UILibrary.NAMESPACE.equals(taglibURI) || UILibrary.ALIAS_NAMESPACE.equals(taglibURI)) );
+
Location location = new Location(alias, 0, 0);
int len = attributes.size();
+ if (tagContainParams && attributes.containsKey("params"))
+ {
+ len = len-1;
+ }
+
TagAttribute[] ta = new TagAttribute[len];
int i = 0;
+ Map<String, Object> paramsMap = null;
for (Map.Entry<String, Object> entry : attributes.entrySet())
{
String stringValue = null;
- if (entry.getValue() instanceof ValueExpression)
- {
- stringValue = ((ValueExpression)entry.getValue()).getExpressionString();
- }
- else if (entry.getValue() instanceof MethodExpression)
+
+ if (tagContainParams && "params".equals(entry.getKey()))
{
- stringValue = ((MethodExpression)entry.getValue()).getExpressionString();
+ paramsMap = (Map<String, Object>) entry.getValue();
}
- else if (entry.getValue() != null)
+ else
{
- stringValue = entry.getValue().toString();
+ if (entry.getValue() instanceof ValueExpression)
+ {
+ stringValue = ((ValueExpression)entry.getValue()).getExpressionString();
+ }
+ else if (entry.getValue() instanceof MethodExpression)
+ {
+ stringValue = ((MethodExpression)entry.getValue()).getExpressionString();
+ }
+ else if (entry.getValue() != null)
+ {
+ stringValue = entry.getValue().toString();
+ }
+ ta[i] = new TagAttributeImpl(location, "", entry.getKey(), entry.getKey(), stringValue);
+ i++;
}
- ta[i] = new TagAttributeImpl(location, "", entry.getKey(), entry.getKey(), stringValue);
- i++;
}
mngr.pushTag(new Tag(location, taglibURI, tagName, "oamf:"+tagName, new TagAttributesImpl(ta)));
+
+ if (tagContainParams && paramsMap != null)
+ {
+ for (Map.Entry<String, Object> entry : paramsMap.entrySet())
+ {
+ TagAttribute[] tap = new TagAttribute[2];
+ String stringValue = null;
+ if (entry.getValue() instanceof ValueExpression)
+ {
+ stringValue = ((ValueExpression)entry.getValue()).getExpressionString();
+ }
+ else if (entry.getValue() instanceof MethodExpression)
+ {
+ stringValue = ((MethodExpression)entry.getValue()).getExpressionString();
+ }
+ else if (entry.getValue() != null)
+ {
+ stringValue = entry.getValue().toString();
+ }
+ tap[0] = new TagAttributeImpl(location, "", "name", "name", entry.getKey());
+ tap[1] = new TagAttributeImpl(location, "", "value", "value", stringValue);
+ mngr.pushTag(new Tag(location, UILibrary.NAMESPACE, "param", "oamf:param", new TagAttributesImpl(tap)));
+ mngr.popTag();
+ }
+ }
mngr.popTag();
mngr.popNamespace(prefix);
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java?rev=1744645&r1=1744644&r2=1744645&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java Thu May 19 23:39:41 2016
@@ -41,6 +41,7 @@ import org.apache.myfaces.view.facelets.
import org.apache.myfaces.view.facelets.pss.acid.managed.CustomSessionBean;
import org.apache.myfaces.view.facelets.pss.acid.managed.ForEachBean;
import org.apache.myfaces.view.facelets.pss.acid.managed.ResourceDependencyBean;
+import org.apache.myfaces.view.facelets.pss.acid.managed.TestBean;
import org.junit.Assert;
import org.junit.Test;
@@ -954,22 +955,34 @@ public class AcidMyFacesRequestTestCase
UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
Assert.assertEquals(1, comp.getChildCount());
UIComponent wrapper = comp.getChildren().get(0);
- Assert.assertEquals(2, wrapper.getChildCount());
+ Assert.assertEquals(3, wrapper.getChildCount());
Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
- Assert.assertTrue(new String(writer1.content()).contains("Dynamically added markup"));
+ String content = new String(writer1.content());
+ Assert.assertTrue(content.contains("Dynamically added markup"));
+ Assert.assertTrue(content.contains("Value in param1: value1"));
+ Assert.assertTrue(content.contains("Value in param2: value2"));
UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
client.submit(button);
- processLifecycleExecuteAndRender();
+ processLifecycleExecute();
+
+ TestBean bean = facesContext.getApplication().evaluateExpressionGet(
+ facesContext, "#{testBean}", TestBean.class);
+ bean.setParam2("otherValue2");
+
+ processLifecycleRender();
comp = facesContext.getViewRoot().findComponent("mainForm:component");
Assert.assertEquals(1, comp.getChildCount());
wrapper = comp.getChildren().get(0);
- Assert.assertEquals(2, wrapper.getChildCount());
+ Assert.assertEquals(3, wrapper.getChildCount());
Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
- Assert.assertTrue(new String(writer2.content()).contains("Dynamically added markup"));
+ String content2 = new String(writer2.content());
+ Assert.assertTrue(content2.contains("Dynamically added markup"));
+ Assert.assertTrue(content2.contains("Value in param1: value1"));
+ Assert.assertTrue(content2.contains("Value in param2: otherValue2"));
endRequest();
}
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleIncludeVDL2.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleIncludeVDL2.java?rev=1744645&r1=1744644&r2=1744645&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleIncludeVDL2.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleIncludeVDL2.java Thu May 19 23:39:41 2016
@@ -78,6 +78,11 @@ public class UIAddSimpleIncludeVDL2 exte
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("src", "/addSimpleIncludeVDL_2_1.xhtml");
+ Map<String, Object> paramsMap = new HashMap<String, Object>();
+ paramsMap.put("param1", "value1");
+ paramsMap.put("param2", facesContext.getApplication().getExpressionFactory().createValueExpression(
+ facesContext.getELContext(), "#{testBean.param2}" ,String.class));
+ attributes.put("params", paramsMap);
UIComponent component = vdl.createComponent(facesContext,
"http://java.sun.com/jsf/facelets",
"include", attributes);
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/TestBean.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/TestBean.java?rev=1744645&r1=1744644&r2=1744645&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/TestBean.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/TestBean.java Thu May 19 23:39:41 2016
@@ -34,9 +34,12 @@ public class TestBean
{
private List<ValueHolder> values = new ArrayList<ValueHolder>();
+
+ private String param2;
public TestBean()
{
+ param2 = "value2";
}
@PostConstruct
@@ -63,5 +66,21 @@ public class TestBean
this.values = values;
}
+ /**
+ * @return the param2
+ */
+ public String getParam2()
+ {
+ return param2;
+ }
+
+ /**
+ * @param param2 the param2 to set
+ */
+ public void setParam2(String param2)
+ {
+ this.param2 = param2;
+ }
+
}
Modified: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleIncludeVDL_2_1.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleIncludeVDL_2_1.xhtml?rev=1744645&r1=1744644&r2=1744645&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleIncludeVDL_2_1.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleIncludeVDL_2_1.xhtml Thu May 19 23:39:41 2016
@@ -19,5 +19,7 @@
xmlns:test="http://testcomponent">
Dynamically added markup
<h:outputText value="Dynamically added child"/>
+Value in param1: #{param1}
+Value in param2: #{param2}
</ui:component>