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 07025e9377 Load the actions of a menu item
07025e9377 is described below
commit 07025e9377d1905ff773e4eb1f5ab85561587ac7
Author: Mridul Pathak <[email protected]>
AuthorDate: Thu Oct 29 19:51:50 2026 +0530
Load the actions of a menu item
ModelMenuItem looked for the <actions> element of a menu-item inside its
condition instead of the menu-item element itself, where the widget-menu schema
puts it, so the actions of a menu item were never loaded or run. They are now
read from the menu-item element. A unit test covers it.
---
.../apache/ofbiz/widget/model/ModelMenuItem.java | 2 +-
.../ofbiz/widget/model/ModelMenuItemTest.java | 47 ++++++++++++++++++++++
2 files changed, 48 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 57f52c2302..2e2cfc66d1 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
@@ -157,7 +157,7 @@ public class ModelMenuItem extends ModelWidget {
this.condition = null;
}
// read all actions under the "actions" element
- Element actionsElement = UtilXml.firstChildElement(conditionElement,
"actions");
+ Element actionsElement = UtilXml.firstChildElement(menuItemElement,
"actions");
if (actionsElement != null) {
this.actions = AbstractModelAction.readSubActions(this,
actionsElement);
} else {
diff --git
a/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuItemTest.java
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuItemTest.java
new file mode 100644
index 0000000000..b75dd399d8
--- /dev/null
+++
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelMenuItemTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.HashMap;
+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 ModelMenuItemTest {
+
+ private static final String MENU = "<menu name=\"Test\">"
+ + "<menu-item name=\"main\" title=\"Main\">"
+ + "<actions><set field=\"itemAction\" value=\"done\"/></actions>"
+ + "<link target=\"main\"/>"
+ + "</menu-item>"
+ + "</menu>";
+
+ @Test
+ public void testMenuItemActionsAreLoaded() throws Exception {
+ Element menuElement = UtilXml.readXmlDocument(MENU, false,
true).getDocumentElement();
+ ModelMenuItem item = new ModelMenu(menuElement, "test",
null).getModelMenuItemByName("main");
+ Assertions.assertEquals(1, item.getActions().size(), "Item actions
should be read from the menu-item element");
+ Map<String, Object> context = new HashMap<>();
+ AbstractModelAction.runSubActions(item.getActions(), context);
+ Assertions.assertEquals("done", context.get("itemAction"), "Item
action should run");
+ }
+}