You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2020/04/22 10:35:21 UTC

[myfaces-tobago] branch tobago-4.x updated: fix: rendered attribute for composite components in segment layout

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-4.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-4.x by this push:
     new e40f0ab  fix: rendered attribute for composite components in segment layout
e40f0ab is described below

commit e40f0ab92a7e98d81e7067b9ff2f8eb5f85386ab
Author: Henning Nöth <hn...@apache.org>
AuthorDate: Wed Apr 22 12:08:36 2020 +0200

    fix: rendered attribute for composite components in segment layout
    
    * impl fix
    * add a example
    * add a test (rewrite for QUnit)
    
    Issue: TOBAGO-2034
    (cherry picked from commit be7e0a545b76f5fec6568f5d777e68251d57da6b)
---
 .../apache/myfaces/tobago/util/ComponentUtils.java |  6 +-
 .../Composite_Components.test.js                   | 82 ++++++++++++++++++++++
 .../Composite_Components.xhtml                     | 67 ++++++++++++++++++
 .../resources/demo-components/inputAsText.xhtml    | 34 +++++++++
 4 files changed, 187 insertions(+), 2 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
index 9ba067d..807b3c1 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
@@ -563,7 +563,7 @@ public final class ComponentUtils {
   }
 
   public static RendererBase getRenderer(final FacesContext facesContext, final String family,
-                                         final String rendererType) {
+      final String rendererType) {
     if (rendererType == null) {
       return null;
     }
@@ -895,7 +895,8 @@ public final class ComponentUtils {
 
   private static void addLayoutChildren(final UIComponent component, final List<UIComponent> result) {
     for (final UIComponent child : component.getChildren()) {
-      if (child instanceof Visual && !((Visual) child).isPlain()) {
+      if (child instanceof Visual && !((Visual) child).isPlain()
+          || (UIComponent.isCompositeComponent(child) && !child.isRendered())) {
         result.add(child);
       } else {
         // Child seems to be transparent for layout, like UIForm with "plain" set.
@@ -916,6 +917,7 @@ public final class ComponentUtils {
 
   /**
    * returns the "confirmation" attribute or the value of the "confirmation" facet of a component.
+   *
    * @since Tobago 4.4.0
    */
   public static String getConfirmation(final UIComponent component) {
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.test.js
new file mode 100644
index 0000000..a422b40
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.test.js
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+QUnit.test("no layout manager", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:noLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:noLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:noLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
+
+QUnit.test("flowlayout", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:flowLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:flowLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:flowLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
+
+QUnit.test("flexlayout", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:flexLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:flexLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:flexLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
+
+QUnit.test("segmentlayout", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:segLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:segLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:segLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
+
+QUnit.test("gridlayout", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:gridLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:gridLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:gridLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
+
+QUnit.test("splitlayout", function (assert) {
+  var inFn = jQueryFrameFn("#page\\:mainForm\\:splitLayoutIn\\:in\\:\\:field");
+  var outFn = jQueryFrameFn("#page\\:mainForm\\:splitLayoutOut\\:out");
+  var notRenderedFn = jQueryFrameFn("#page\\:mainForm\\:splitLayoutNotRendered\\:in\\:\\:field");
+  assert.expect(3);
+
+  assert.equal(inFn().length, 1);
+  assert.equal(outFn().length, 1);
+  assert.equal(notRenderedFn().length, 0);
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.xhtml
new file mode 100644
index 0000000..02b47b3
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/5500-compositeComponent/Composite_Components.xhtml
@@ -0,0 +1,67 @@
+<?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 template="/main.xhtml"
+                xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:dc="http://java.sun.com/jsf/composite/demo-components"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://java.sun.com/jsf/facelets">
+  <ui:param name="title" value="Composite Components"/>
+
+  <tc:section label="no layout manager">
+    <dc:inputAsText id="noLayoutIn" value="tc:in"/>
+    <dc:inputAsText id="noLayoutOut" value="tc:out" asText="true"/>
+    <dc:inputAsText id="noLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+  </tc:section>
+  <tc:section label="flowLayout">
+    <tc:flowLayout>
+      <dc:inputAsText id="flowLayoutIn" value="tc:in"/>
+      <dc:inputAsText id="flowLayoutOut" value="tc:out" asText="true"/>
+      <dc:inputAsText id="flowLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+    </tc:flowLayout>
+  </tc:section>
+  <tc:section label="flexLayout">
+    <tc:flexLayout columns="1fr 1fr">
+      <dc:inputAsText id="flexLayoutIn" value="tc:in"/>
+      <dc:inputAsText id="flexLayoutOut" value="tc:out" asText="true"/>
+      <dc:inputAsText id="flexLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+    </tc:flexLayout>
+  </tc:section>
+  <tc:section label="segmentLayout">
+    <tc:segmentLayout medium="6seg">
+      <dc:inputAsText id="segLayoutIn" value="tc:in"/>
+      <dc:inputAsText id="segLayoutOut" value="tc:out" asText="true"/>
+      <dc:inputAsText id="segLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+    </tc:segmentLayout>
+  </tc:section>
+  <tc:section label="gridLayout">
+    <tc:gridLayout columns="1fr 1fr" rows="auto">
+      <dc:inputAsText id="gridLayoutIn" value="tc:in"/>
+      <dc:inputAsText id="gridLayoutOut" value="tc:out" asText="true"/>
+      <dc:inputAsText id="gridLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+    </tc:gridLayout>
+  </tc:section>
+  <tc:section label="splitLayout">
+    <tc:splitLayout columns="1fr 1fr">
+      <dc:inputAsText id="splitLayoutIn" value="tc:in"/>
+      <dc:inputAsText id="splitLayoutOut" value="tc:out" asText="true"/>
+      <dc:inputAsText id="splitLayoutNotRendered" value="this should NOT be rendered" rendered="false"/>
+    </tc:splitLayout>
+  </tc:section>
+</ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/inputAsText.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/inputAsText.xhtml
new file mode 100644
index 0000000..de53855
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/inputAsText.xhtml
@@ -0,0 +1,34 @@
+<?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.
+-->
+<!DOCTYPE html
+        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns:cc="http://java.sun.com/jsf/composite"
+      xmlns:tc="http://myfaces.apache.org/tobago/component">
+<cc:interface>
+  <cc:attribute name="label"/>
+  <cc:attribute name="value"/>
+  <cc:attribute name="asText" default="false"/>
+</cc:interface>
+<cc:implementation>
+  <tc:panel id="wrapper">
+    <tc:in id="in" label="#{cc.attrs.label}" value="#{cc.attrs.value}" rendered="#{!cc.attrs.asText}"/>
+    <tc:out id="out" label="#{cc.attrs.label}" value="#{cc.attrs.value}" rendered="#{cc.attrs.asText}"/>
+  </tc:panel>
+</cc:implementation>
+</html>