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

mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b429f618ca Keep the names of menu items inherited through menu extends
b429f618ca is described below

commit b429f618cab78aab8979409620f4eb53b1248337
Author: Mridul Pathak <[email protected]>
AuthorDate: Thu Oct 29 17:25:49 2026 +0530

    Keep the names of menu items inherited through menu extends
    
    When a menu extends another one, each inherited menu item was copied under 
a new name made of the child menu's name and the item's name. A menu-item of 
the same name in the child menu was then added next to the inherited one 
instead of overriding it, and an inherited item never matched the selected item 
name, so it was never rendered as selected. The copy now keeps the item's own 
name; it still belongs to the child menu. A unit test covers both cases.
---
 .../apache/ofbiz/widget/model/ModelMenuItem.java   |  2 +-
 .../apache/ofbiz/widget/model/ModelMenuTest.java   | 60 ++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java
index 6306570589..57f52c2302 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java
@@ -167,7 +167,7 @@ public class ModelMenuItem extends ModelWidget {
     }
 
     public ModelMenuItem(ModelMenuItem originMenuItem, ModelMenu modelMenu, 
ModelMenuItem parentMenuItem) {
-        super(modelMenu.getName() + originMenuItem.getName());
+        super(originMenuItem.getName());
         this.modelMenu = modelMenu;
         this.parentMenuItem = parentMenuItem;
         this.entityName = originMenuItem.entityName;
diff --git 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuTest.java
 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuTest.java
new file mode 100644
index 0000000000..9234629817
--- /dev/null
+++ 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+package org.apache.ofbiz.widget.model;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ofbiz.base.util.UtilXml;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Element;
+
+public final class ModelMenuTest {
+
+    private static final String MENUS = "<menus>"
+            + "<menu name=\"Parent\" 
selected-menuitem-context-field-name=\"headerItem\">"
+            + "<menu-item name=\"main\" title=\"Main\"><link 
target=\"main\"/></menu-item>"
+            + "<menu-item name=\"other\" title=\"Other\"><link 
target=\"other\"/></menu-item>"
+            + "</menu>"
+            + "<menu name=\"Child\" extends=\"Parent\">"
+            + "<menu-item name=\"main\" title=\"Child main\"/>"
+            + "</menu>"
+            + "</menus>";
+
+    private static ModelMenu childMenu() throws Exception {
+        Element rootElement = UtilXml.readXmlDocument(MENUS, false, 
true).getDocumentElement();
+        return new ModelMenu(UtilXml.childElementList(rootElement, 
"menu").get(1), "test", null);
+    }
+
+    @Test
+    public void testInheritedMenuItemKeepsItsName() throws Exception {
+        ModelMenuItem other = childMenu().getModelMenuItemByName("other");
+        Assertions.assertNotNull(other, "Inherited item should keep its name");
+        Assertions.assertTrue(other.isSelected(Map.of("headerItem", "other")), 
"Inherited item should be selectable");
+    }
+
+    @Test
+    public void testChildMenuItemOverridesInheritedItem() throws Exception {
+        List<ModelMenuItem> items = childMenu().getMenuItemList();
+        Assertions.assertEquals(2, items.size(), "Child item should replace 
the inherited one");
+        Assertions.assertEquals("main", items.get(0).getName(), "Overridden 
item should keep its position");
+        Assertions.assertEquals("Child main", 
items.get(0).getTitle().getOriginal(), "Child title should win");
+    }
+}

Reply via email to