You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/04/27 15:45:50 UTC

[ofbiz-framework] 01/02: Fixed: Compound-widget not works with condition

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

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

commit 0805e57f08164b4d4dde00dd1d3614bd64b6aa24
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Mon Apr 27 14:31:31 2020 +0200

    Fixed: Compound-widget not works with condition
    
    (OFBIZ-11606)
    
    rootElement is not correct for a compound file, it's necessary to do a
    UtilXml.firstChildElement(rootElement, "forms"); to be correct.
    It's done for screen, form but not for grid !
    
    So correction is now added the correct read of rootElement.
    
    Thanks: Olivier
---
 .../java/org/apache/ofbiz/widget/model/GridFactory.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java
index c80c54d..e79217a 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java
@@ -104,6 +104,9 @@ public class GridFactory {
         if (gridFileDoc != null) {
             // read document and construct ModelGrid for each grid element
             Element rootElement = gridFileDoc.getDocumentElement();
+            if (!"forms".equalsIgnoreCase(rootElement.getTagName())) {
+                rootElement = UtilXml.firstChildElement(rootElement, "forms");
+            }
             List<? extends Element> gridElements = UtilXml.childElementList(rootElement, "grid");
             for (Element gridElement : gridElements) {
                 String gridName = gridElement.getAttribute("name");
@@ -120,12 +123,19 @@ public class GridFactory {
     }
 
     public static ModelGrid createModelGrid(Document gridFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) {
-        Element gridElement = UtilXml.firstChildElement(gridFileDoc.getDocumentElement(), "grid", "name", gridName);
+        Element rootElement = gridFileDoc.getDocumentElement();
+        if (!"forms".equalsIgnoreCase(rootElement.getTagName())) {
+            rootElement = UtilXml.firstChildElement(rootElement, "forms");
+        }
+        Element gridElement = UtilXml.firstChildElement(rootElement, "grid", "name", gridName);
         if (gridElement == null) {
             // Backwards compatibility - look for form definition
             gridElement = UtilXml.firstChildElement(gridFileDoc.getDocumentElement(), "form", "name", gridName);
         }
-        return createModelGrid(gridElement, entityModelReader, dispatchContext, gridLocation, gridName);
+        if (gridElement == null) {
+            throw new IllegalArgumentException("Could not find grid with name [" + gridName + "] in class resource [" + gridLocation + "]");
+        }
+        return createModelGrid(gridElement, entityModelReader, visualTheme, dispatchContext, gridLocation, gridName);
     }
 
     public static ModelGrid createModelGrid(Element gridElement, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) {