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 2025/05/05 10:18:45 UTC

(myfaces-tobago) branch tobago-5.x updated: fix(dropdown): composite component

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

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


The following commit(s) were added to refs/heads/tobago-5.x by this push:
     new c9acb84cfa fix(dropdown): composite component
c9acb84cfa is described below

commit c9acb84cfa929ff7ded22b5d03a941c78474569f
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Mon May 5 10:27:37 2025 +0200

    fix(dropdown): composite component
    
    * improve test
    * fix visiting dropdown tree
    
    Issue: TOBAGO-2415
---
 .../renderkit/renderer/CommandRendererBase.java    |  4 ++-
 .../900-test/4200-dropdown/Dropdown.test.js        |  8 +++++-
 .../content/900-test/4200-dropdown/Dropdown.xhtml  |  2 ++
 .../resources/demo-components/twoLinks.xhtml       | 31 ++++++++++++++++++++++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
index d04401b585..2b256759be 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
@@ -203,7 +203,6 @@ public void encodeChildrenInternal(final FacesContext facesContext, final T comp
       writer.writeAttribute(Arias.LABELLEDBY, component.getFieldId(facesContext), false);
       writer.writeAttribute(HtmlAttributes.NAME, component.getClientId(facesContext), false);
 
-
       RenderChildrenCommands visitor =
           new RenderChildrenCommands(facesContext, writer, component.getClientId(facesContext));
       component.visitTree(
@@ -307,6 +306,9 @@ public VisitResult visit(VisitContext context, UIComponent target) {
             }
             insideEnd(facesContext, HtmlElements.COMMAND);
             // XXX may refactor / cleanup
+          } else if (UIComponent.isCompositeComponent(target)) {
+            UIComponent facet = target.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+            return visit(context, facet);
           } else {
             try {
               writer.startElement(HtmlElements.DIV);
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.test.js
index 666bfee438..c13aa0ca02 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.test.js
@@ -141,9 +141,15 @@ it("Composite component inside dropdown menu", function () {
   expect(tobagoDropdown().children[1].classList.contains("tobago-dropdown-menu")).toBeTrue();
 
   const tobagoDropdownMenu = tobagoDropdown().children[1];
-  expect(tobagoDropdownMenu.children.length).toEqual(2);
+  expect(tobagoDropdownMenu.children.length).toEqual(5);
   expect(tobagoDropdownMenu.children[0].tagName).toEqual("TOBAGO-DROPDOWN");
   expect(tobagoDropdownMenu.children[0].id).toContain("page:mainForm:ccddEntry");
   expect(tobagoDropdownMenu.children[1].tagName).toEqual("TOBAGO-DROPDOWN");
   expect(tobagoDropdownMenu.children[1].id).toContain("page:mainForm:compositeComponent:");
+  expect(tobagoDropdownMenu.children[2].tagName).toEqual("DIV");
+  expect(tobagoDropdownMenu.children[2].classList.contains("dropdown-item")).toBeTrue();
+  expect(tobagoDropdownMenu.children[3].tagName).toEqual("BUTTON");
+  expect(tobagoDropdownMenu.children[3].classList.contains("tobago-link")).toBeTrue();
+  expect(tobagoDropdownMenu.children[4].tagName).toEqual("BUTTON");
+  expect(tobagoDropdownMenu.children[4].classList.contains("tobago-link")).toBeTrue();
 });
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.xhtml
index 7ba57f8f4a..f8949d5b09 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/4200-dropdown/Dropdown.xhtml
@@ -128,5 +128,7 @@
       <tc:link label="Entry 2"/>
     </tc:link>
     <dc:dropdown-dummy id="compositeComponent" label="Sub Composite"/>
+    <dc:output id="compositeOutput" name="This text must be inside a div.dropdown-item element."/>
+    <dc:twoLinks id="compositeTwoLinks" labelOne="Entry 1" labelTwo="Entry 2"/>
   </tc:button>
 </ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/twoLinks.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/twoLinks.xhtml
new file mode 100644
index 0000000000..33844ee1c3
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/twoLinks.xhtml
@@ -0,0 +1,31 @@
+<?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://xmlns.jcp.org/jsf/composite"
+      xmlns:tc="http://myfaces.apache.org/tobago/component">
+<cc:interface>
+  <cc:attribute name="labelOne"/>
+  <cc:attribute name="labelTwo"/>
+</cc:interface>
+<cc:implementation>
+  <tc:link label="#{cc.attrs.labelOne}" omit="true"/>
+  <tc:link label="#{cc.attrs.labelTwo}" omit="true"/>
+</cc:implementation>
+</html>