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 2018/04/11 13:53:11 UTC

[myfaces-tobago] branch master updated: TOBAGO-1881 Label-Facet of tc:section and tc:box are different

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5aee33d  TOBAGO-1881 Label-Facet of tc:section and tc:box are different
5aee33d is described below

commit 5aee33d4973a07b703333cd69ac6af41d6731660
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Apr 11 15:51:33 2018 +0200

    TOBAGO-1881 Label-Facet of tc:section and tc:box are different
    
    * fix for tc:operation used in label facet
    * test for accordion example
---
 .../component/AbstractUICollapsiblePanel.java      |  12 ++
 .../taglib/component/SectionTagDeclaration.java    |   6 +-
 .../20-component/050-container/10-box/box.test.js  | 182 +++++++++++++++++++++
 .../20-component/050-container/10-box/box.xhtml    |  25 +--
 .../myfaces/tobago/example/demo/QUnitTests.java    |   6 +
 5 files changed, 219 insertions(+), 12 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICollapsiblePanel.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICollapsiblePanel.java
index 6b37774..5a2d7ff 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICollapsiblePanel.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICollapsiblePanel.java
@@ -44,6 +44,10 @@ public abstract class AbstractUICollapsiblePanel extends AbstractUIPanelBase {
       if (bar != null) {
         bar.processDecodes(facesContext);
       }
+      final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
+      if (label != null) {
+        label.processDecodes(facesContext);
+      }
     }
   }
 
@@ -56,6 +60,10 @@ public abstract class AbstractUICollapsiblePanel extends AbstractUIPanelBase {
       if (bar != null) {
         bar.processValidators(facesContext);
       }
+      final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
+      if (label != null) {
+        label.processValidators(facesContext);
+      }
     }
   }
 
@@ -68,6 +76,10 @@ public abstract class AbstractUICollapsiblePanel extends AbstractUIPanelBase {
       if (bar != null) {
         bar.processUpdates(facesContext);
       }
+      final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
+      if (label != null) {
+        label.processUpdates(facesContext);
+      }
     }
   }
 
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java
index 8a1c5e6..0845d28 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java
@@ -48,8 +48,10 @@ import org.apache.myfaces.tobago.internal.taglib.declaration.IsVisual;
     },
     facets = {
         @Facet(name = Facets.LABEL,
-            description = "This facet contains a UILabel",
-            allowedChildComponenents = "org.apache.myfaces.tobago.Label")})
+            description = "Contains some code to be placed in the header at the label position."),
+        @Facet(name = Facets.BAR,
+            description = "Contains some code to be placed in the header at the bar position.")
+    })
 
 public interface SectionTagDeclaration
     extends HasIdBindingAndRendered, HasLabel, IsVisual, HasImage, IsCollapsed, HasCollapsedMode, HasTip {
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.test.js
new file mode 100644
index 0000000..0949abf
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.test.js
@@ -0,0 +1,182 @@
+/*
+ * 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("Accordion: Box 1: 'hide' to 'show' to 'hide'", function (assert) {
+  assert.expect(9);
+  var done = assert.async(2);
+  var step = 1;
+
+  var $box = jQueryFrame("#page\\:mainForm\\:accordionBox1");
+  var $showBox = jQueryFrame("#page\\:mainForm\\:showBox1");
+  var $hideBox = jQueryFrame("#page\\:mainForm\\:hideBox1");
+  var $boxBody = $box.find(".card-body");
+
+  assert.equal($showBox.length, 1);
+  assert.equal($hideBox.length, 0);
+  assert.equal($boxBody.text().trim().length, 0);
+  $showBox.click();
+
+  jQuery("#page\\:testframe").load(function () {
+    if (step === 1) {
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+      $boxBody = jQueryFrame($boxBody.selector);
+
+      assert.equal($showBox.length, 0);
+      assert.equal($hideBox.length, 1);
+      assert.notEqual($boxBody.text().trim().length, 0);
+
+      $hideBox.click();
+
+      step++;
+      done();
+    } else if (step === 2) {
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+      $boxBody = jQueryFrame($boxBody.selector);
+
+      assert.equal($showBox.length, 1);
+      assert.equal($hideBox.length, 0);
+      assert.equal($boxBody.text().trim().length, 0);
+
+      step++;
+      done();
+    }
+  });
+});
+
+QUnit.test("Accordion: Box 2: 'hide' to 'show' to 'hide'", function (assert) {
+  assert.expect(9);
+  var done = assert.async(2);
+  var step = 1;
+
+  var $box = jQueryFrame("#page\\:mainForm\\:accordionBox2");
+  var $showBox = jQueryFrame("#page\\:mainForm\\:showBox2");
+  var $hideBox = jQueryFrame("#page\\:mainForm\\:hideBox2");
+  var $boxBody = $box.find(".card-body");
+
+  assert.equal($showBox.length, 1);
+  assert.equal($hideBox.length, 0);
+  assert.equal($boxBody.text().trim().length, 0);
+  $showBox.click();
+
+  waitForAjax(function () {
+    $showBox = jQueryFrame($showBox.selector);
+    $hideBox = jQueryFrame($hideBox.selector);
+    $boxBody = jQueryFrame($boxBody.selector);
+
+    return step === 1
+        && $showBox.length === 0
+        && $hideBox.length === 1
+        && $boxBody.text().trim().length !== 0;
+  }, function () {
+    $showBox = jQueryFrame($showBox.selector);
+    $hideBox = jQueryFrame($hideBox.selector);
+    $boxBody = jQueryFrame($boxBody.selector);
+
+    assert.equal($showBox.length, 0);
+    assert.equal($hideBox.length, 1);
+    assert.notEqual($boxBody.text().trim().length, 0);
+
+    $hideBox.click();
+
+    waitForAjax(function () {
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+      $boxBody = jQueryFrame($boxBody.selector);
+
+      return step === 2
+          && $showBox.length === 1
+          && $hideBox.length === 0
+          && $boxBody.text().trim().length === 0;
+    }, function () {
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+      $boxBody = jQueryFrame($boxBody.selector);
+
+      assert.equal($showBox.length, 1);
+      assert.equal($hideBox.length, 0);
+      assert.equal($boxBody.text().trim().length, 0);
+
+      step++;
+      done();
+    });
+    step++;
+    done();
+  });
+});
+
+QUnit.test("Accordion: Box 3: 'hide' to 'show' to 'hide'", function (assert) {
+  assert.expect(9);
+  var done = assert.async(2);
+  var step = 1;
+
+  var $box = jQueryFrame("#page\\:mainForm\\:accordionBox3");
+  var $showBox = jQueryFrame("#page\\:mainForm\\:showBox3");
+  var $hideBox = jQueryFrame("#page\\:mainForm\\:hideBox3");
+  var $boxBody = $box.find(".card-body");
+
+  assert.ok($box.hasClass("tobago-collapsed"));
+  assert.equal($showBox.length, 1);
+  assert.equal($hideBox.length, 0);
+  $showBox.click();
+
+  waitForAjax(function () {
+    $box = jQueryFrame($box.selector);
+    $showBox = jQueryFrame($showBox.selector);
+    $hideBox = jQueryFrame($hideBox.selector);
+
+    return step === 1
+        && !$box.hasClass("tobago-collapsed")
+        && $showBox.length === 0
+        && $hideBox.length === 1;
+  }, function () {
+    $box = jQueryFrame($box.selector);
+    $showBox = jQueryFrame($showBox.selector);
+    $hideBox = jQueryFrame($hideBox.selector);
+
+    assert.notOk($box.hasClass("tobago-collapsed"));
+    assert.equal($showBox.length, 0);
+    assert.equal($hideBox.length, 1);
+
+    $hideBox.click();
+
+    waitForAjax(function () {
+      $box = jQueryFrame($box.selector);
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+
+      return step === 2
+          && $box.hasClass("tobago-collapsed")
+          && $showBox.length === 1
+          && $hideBox.length === 0;
+    }, function () {
+      $box = jQueryFrame($box.selector);
+      $showBox = jQueryFrame($showBox.selector);
+      $hideBox = jQueryFrame($hideBox.selector);
+
+      assert.ok($box.hasClass("tobago-collapsed"));
+      assert.equal($showBox.length, 1);
+      assert.equal($hideBox.length, 0);
+
+      step++;
+      done();
+    });
+    step++;
+    done();
+  });
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.xhtml
index 0368d24..82dca4d1 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/050-container/10-box/box.xhtml
@@ -88,15 +88,20 @@
   </tc:section>
 
   <tc:section label="Accordion">
-    <tc:box id="accordionBox1" collapsedMode="hidden" collapsed="#{boxController.box1collapsed}">
+    <p>This example show collapsible/expandable boxes using the label facet.</p>
+    <p>Expanding/collapsing the first box, a full server request is executed.
+      The other two boxes are reloaded with an ajax request.</p>
+    <p>In the collapsed form the last box only hide the content with CSS.
+      The boxes 'Box 1' and 'Box 2' don't render the content at all.</p>
+    <p>See <tc:link label="Collapsible Concept" outcome="/content/30-concept/53-collapsible/collapsible.xhtml"/>
+      for more information about the collapsible concept.</p>
+    <tc:box id="accordionBox1" collapsedMode="absent" collapsed="#{boxController.box1collapsed}">
       <f:facet name="label">
-        <tc:link label="Box 1" rendered="#{boxController.box1collapsed}">
+        <tc:link id="showBox1" label="Box 1" rendered="#{boxController.box1collapsed}">
           <tc:operation for="accordionBox1" name="show"/>
-          <f:ajax execute="accordionBox1" render="accordionBox1"/>
         </tc:link>
-        <tc:link label="Box 1" rendered="#{!boxController.box1collapsed}">
+        <tc:link id="hideBox1" label="Box 1" rendered="#{!boxController.box1collapsed}">
           <tc:operation for="accordionBox1" name="hide"/>
-          <f:ajax execute="accordionBox1" render="accordionBox1"/>
         </tc:link>
       </f:facet>
       <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
@@ -106,13 +111,13 @@
         sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
         takimata sanctus est Lorem ipsum dolor sit amet.</p>
     </tc:box>
-    <tc:box id="accordionBox2" collapsedMode="hidden" collapsed="#{boxController.box2collapsed}">
+    <tc:box id="accordionBox2" collapsedMode="absent" collapsed="#{boxController.box2collapsed}">
       <f:facet name="label">
-        <tc:link label="Box 2" rendered="#{boxController.box2collapsed}">
+        <tc:link id="showBox2" label="Box 2" rendered="#{boxController.box2collapsed}">
           <tc:operation for="accordionBox2" name="show"/>
           <f:ajax execute="accordionBox2" render="accordionBox2"/>
         </tc:link>
-        <tc:link label="Box 2" rendered="#{!boxController.box2collapsed}">
+        <tc:link id="hideBox2" label="Box 2" rendered="#{!boxController.box2collapsed}">
           <tc:operation for="accordionBox2" name="hide"/>
           <f:ajax execute="accordionBox2" render="accordionBox2"/>
         </tc:link>
@@ -126,11 +131,11 @@
     </tc:box>
     <tc:box id="accordionBox3" collapsedMode="hidden" collapsed="#{boxController.box3collapsed}">
       <f:facet name="label">
-        <tc:link label="Box 3" rendered="#{boxController.box3collapsed}">
+        <tc:link id="showBox3" label="Box 3" rendered="#{boxController.box3collapsed}">
           <tc:operation for="accordionBox3" name="show"/>
           <f:ajax execute="accordionBox3" render="accordionBox3"/>
         </tc:link>
-        <tc:link label="Box 3" rendered="#{!boxController.box3collapsed}">
+        <tc:link id="hideBox3" label="Box 3" rendered="#{!boxController.box3collapsed}">
           <tc:operation for="accordionBox3" name="hide"/>
           <f:ajax execute="accordionBox3" render="accordionBox3"/>
         </tc:link>
diff --git a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java
index 22bf908..5b51ee6 100644
--- a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java
+++ b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java
@@ -401,6 +401,12 @@ public class QUnitTests {
   }
 
   @Test
+  public void box() throws UnsupportedEncodingException, InterruptedException {
+    final String page = "content/20-component/050-container/10-box/box.xhtml";
+    runStandardTest(page);
+  }
+
+  @Test
   public void popup() throws UnsupportedEncodingException, InterruptedException {
     final String page = "content/20-component/060-popup/popup.xhtml";
     runStandardTest(page);

-- 
To stop receiving notification emails like this one, please contact
hnoeth@apache.org.