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

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


The following commit(s) were added to refs/heads/release24.09 by this push:
     new 4590974d34 Give a form its own copies of the field groups it inherits
4590974d34 is described below

commit 4590974d34dbc9b57e8c1a44d598f35c5bc2503d
Author: Mridul Pathak <[email protected]>
AuthorDate: Wed Oct 28 21:38:51 2026 +0530

    Give a form its own copies of the field groups it inherits
    
    When a form extended another, it reused the parent's FieldGroup instances, 
and each FieldGroup keeps the form that created it, so the child's inherited 
groups opened and closed the single-form wrapper with the parent form and 
decided whether to show a group from the parent's fields and use-when 
conditions. The child now copies each inherited FieldGroup for itself, keeping 
its id, style, title and collapsible flags, and maps the inherited field names 
to the copies; banners hold no form [...]
---
 .../org/apache/ofbiz/widget/model/ModelForm.java   | 25 ++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
index 92b27ad4d2..a07e9ded2a 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -490,12 +491,19 @@ public abstract class ModelForm extends ModelWidget {
             }
         }
         Map<String, FieldGroupBase> fieldGroupMap = new HashMap<>();
-        if (parentModel != null) {
-            fieldGroupMap.putAll(parentModel.fieldGroupMap);
-        }
         ArrayList<FieldGroupBase> fieldGroupList = new ArrayList<>();
         if (parentModel != null) {
-            fieldGroupList.addAll(parentModel.fieldGroupList);
+            // Copy the parent's field groups so that they render with this 
form; banners hold no form and are shared
+            Map<FieldGroupBase, FieldGroupBase> inheritedFieldGroups = new 
IdentityHashMap<>();
+            for (FieldGroupBase parentFieldGroup : parentModel.fieldGroupList) 
{
+                FieldGroupBase fieldGroup = parentFieldGroup instanceof 
FieldGroup
+                        ? new FieldGroup((FieldGroup) parentFieldGroup, this) 
: parentFieldGroup;
+                inheritedFieldGroups.put(parentFieldGroup, fieldGroup);
+                fieldGroupList.add(fieldGroup);
+            }
+            for (Map.Entry<String, FieldGroupBase> entry : 
parentModel.fieldGroupMap.entrySet()) {
+                fieldGroupMap.put(entry.getKey(), 
inheritedFieldGroups.getOrDefault(entry.getValue(), entry.getValue()));
+            }
         }
         ArrayList<String> lastOrderFields = new ArrayList<>();
         if (parentModel != null) {
@@ -2142,6 +2150,15 @@ public abstract class ModelForm extends ModelWidget {
             this.initiallyCollapsed = initiallyCollapsed;
         }
 
+        private FieldGroup(FieldGroup parentFieldGroup, ModelForm modelForm) {
+            this.modelForm = modelForm;
+            this.id = parentFieldGroup.id;
+            this.style = parentFieldGroup.style;
+            this.title = parentFieldGroup.title;
+            this.collapsible = parentFieldGroup.collapsible;
+            this.initiallyCollapsed = parentFieldGroup.initiallyCollapsed;
+        }
+
         /**
          * Collapsible boolean.
          * @return the boolean

Reply via email to