You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2022/06/17 09:22:35 UTC

[ofbiz-framework] branch release22.01 updated: Fixed: MenuItem doesn't follow correctly extended informations (OFBIZ-12628)

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

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


The following commit(s) were added to refs/heads/release22.01 by this push:
     new bb57531901 Fixed: MenuItem doesn't follow correctly extended informations (OFBIZ-12628)
bb57531901 is described below

commit bb5753190170b50543c123aef5f3a9d46a1d72e8
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Fri Jun 17 11:19:22 2022 +0200

    Fixed: MenuItem doesn't follow correctly extended informations (OFBIZ-12628)
    
    When you use two menus where the second extend the first, menu items and menu links aren't correctly propagated.
    
    The menu items and menu links presents on the second menu already have the first menu on their model.
    
        ****
        <menu name="FirstMenu" extends="CommonInlineBarMenu" extends-resource="component://common/widget/CommonMenus.xml">
            <menu-item name="MyItem">
                <link target="GoAction"/>
            </menu-item>
        </menu>
        <menu name="SecondMenu" extends="FirstMenu"/>
        ****
    
    The result, if during the rendering some information are generated from the menu, in the previous case, it's always the "FirstMenu" that would be use.
    
    Like when your menu generate a hidden-form, the SecondMenu link the bad form
    
        ****
        <form method="post" action="GoAction" onsubmit="javascript:submitFormDisableSubmits(this)" name="SecondMenu">...</form>
        <a href="javascript:ajaxSubmitFormUpdateAreas('FirstMenu', 'xxx')">MyItem</a>
        ****
    
    To solve it and don't break the thread safe pattern, I introduce two new constructor for ModelItem and MenuLink for duplicate the ModelMenuItem and MenuLink in memory with the new parent. With this, the SecondMenu iw now completely duplicated on memory and now share any reference with the extended menu.
    
    Thanks to Marco Rodrigues that detect this problem
---
 .../org/apache/ofbiz/widget/model/ModelMenu.java   |  7 ++-
 .../apache/ofbiz/widget/model/ModelMenuItem.java   | 52 ++++++++++++++++++----
 2 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java
index bf919a5a8e..60a424f241 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java
@@ -170,8 +170,11 @@ public class ModelMenu extends ModelWidget {
                 defaultWidgetStyle = parent.defaultWidgetStyle;
                 defaultTooltipStyle = parent.defaultTooltipStyle;
                 defaultMenuItemName = parent.defaultMenuItemName;
-                menuItemList.addAll(parent.menuItemList);
-                menuItemMap.putAll(parent.menuItemMap);
+                for (ModelMenuItem originModelMenuItem: parent.menuItemList) {
+                    ModelMenuItem modelMenuItem = new ModelMenuItem(originModelMenuItem, this, null);
+                    menuItemList.add(modelMenuItem);
+                    menuItemMap.put(modelMenuItem.getName(), modelMenuItem);
+                }
                 defaultPermissionOperation = parent.defaultPermissionOperation;
                 defaultPermissionEntityAction = parent.defaultPermissionEntityAction;
                 defaultAssociatedContentId = parent.defaultAssociatedContentId;
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 5898bcbfbc..5c54bb3225 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
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -106,15 +107,9 @@ public class ModelMenuItem extends ModelWidget {
         this.tooltipStyle = menuItemElement.getAttribute("tooltip-style");
         this.selectedStyle = menuItemElement.getAttribute("selected-style");
         String hideIfSelected = menuItemElement.getAttribute("hide-if-selected");
-        if (!hideIfSelected.isEmpty()) {
-            if ("true".equalsIgnoreCase(hideIfSelected)) {
-                this.hideIfSelected = Boolean.TRUE;
-            } else {
-                this.hideIfSelected = Boolean.FALSE;
-            }
-        } else {
-            this.hideIfSelected = null;
-        }
+        this.hideIfSelected = !hideIfSelected.isEmpty()
+                ? "true".equalsIgnoreCase(hideIfSelected)
+                : null;
         this.disableIfEmpty = menuItemElement.getAttribute("disable-if-empty");
         this.align = menuItemElement.getAttribute("align");
         this.alignStyle = menuItemElement.getAttribute("align-style");
@@ -171,6 +166,40 @@ public class ModelMenuItem extends ModelWidget {
         this.overrideName = "";
     }
 
+    public ModelMenuItem(ModelMenuItem originMenuItem, ModelMenu modelMenu, ModelMenuItem parentMenuItem) {
+        super(modelMenu.getName() + originMenuItem.getName());
+        this.modelMenu = modelMenu;
+        this.parentMenuItem = parentMenuItem;
+        this.entityName = originMenuItem.entityName;
+        this.title = originMenuItem.title;
+        this.tooltip = originMenuItem.tooltip;
+        this.parentPortalPageId = originMenuItem.parentPortalPageId;
+        this.titleStyle = originMenuItem.titleStyle;
+        this.disabledTitleStyle = originMenuItem.disabledTitleStyle;
+        this.widgetStyle = originMenuItem.widgetStyle;
+        this.tooltipStyle = originMenuItem.tooltipStyle;
+        this.selectedStyle = originMenuItem.selectedStyle;
+        this.hideIfSelected = originMenuItem.hideIfSelected;
+        this.disableIfEmpty = originMenuItem.disableIfEmpty;
+        this.align = originMenuItem.align;
+        this.alignStyle = originMenuItem.alignStyle;
+        this.position = originMenuItem.position;
+        this.associatedContentId = originMenuItem.associatedContentId;
+        this.cellWidth = originMenuItem.cellWidth;
+        this.subMenu = originMenuItem.subMenu;
+        this.link = new MenuLink(originMenuItem.link, this);
+        List<ModelMenuItem> menuItems = new LinkedList<>();
+        originMenuItem.menuItemList.forEach(item -> {
+            menuItems.add(new ModelMenuItem(item, modelMenu, this));
+        });
+        this.menuItemList = menuItems.isEmpty()
+                ? Collections.emptyList()
+                : Collections.unmodifiableList(menuItems);
+        this.condition = originMenuItem.condition;
+        this.actions = originMenuItem.actions;
+        this.overrideName = originMenuItem.overrideName;
+    }
+
     // Portal constructor
     private ModelMenuItem(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) {
         super(portalPage.getString("portalPageId"));
@@ -660,6 +689,11 @@ public class ModelMenuItem extends ModelWidget {
             this.link = new Link(linkElement);
         }
 
+        public MenuLink(MenuLink originLink, ModelMenuItem parentMenuItem) {
+            this.linkMenuItem = parentMenuItem;
+            this.link = originLink.link;
+        }
+
         public MenuLink(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) {
             this.linkMenuItem = parentMenuItem;
             List<Parameter> parameterList = new ArrayList<>();