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

jleroux 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 3b923ad923 Improved: Improvement of the Check xml tag (OFBIZ-12821)
3b923ad923 is described below

commit 3b923ad9231dfa799440ba5507b0abe0246c8c86
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Fri Feb 16 13:54:11 2024 +0100

    Improved: Improvement of the Check xml tag (OFBIZ-12821)
    
    The approach for pre-checking variables is as follows: if a variable with 
the
    same name as the field exists, its value will be used to determine the 
pre-check
    status. There is an example in QuoteForms.xml
    
    Thanks: Maxime Flammang and Nereide team
---
 applications/order/widget/ordermgr/QuoteForms.xml  | 14 +++--
 .../widget/catalog/ImageManagementForms.xml        | 66 +++++++++++-----------
 framework/widget/dtd/widget-form.xsd               |  9 ++-
 .../apache/ofbiz/widget/model/ModelFormField.java  |  1 +
 .../widget/renderer/macro/MacroFormRenderer.java   | 35 ++++++++----
 .../renderer/macro/MacroFormRendererTest.java      | 53 +++++++++++++----
 .../template/macro/HtmlFormMacroLibrary.ftl        |  8 +--
 7 files changed, 121 insertions(+), 65 deletions(-)

diff --git a/applications/order/widget/ordermgr/QuoteForms.xml 
b/applications/order/widget/ordermgr/QuoteForms.xml
index 075a8e7688..89c76b48eb 100644
--- a/applications/order/widget/ordermgr/QuoteForms.xml
+++ b/applications/order/widget/ordermgr/QuoteForms.xml
@@ -17,17 +17,21 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 -->
-<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
+<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xmlns="http://ofbiz.apache.org/Widget-Form"; 
xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form 
http://ofbiz.apache.org/dtds/widget-form.xsd";>
 
     <form name="FindQuotes" target="FindQuote" title="" type="single" 
default-map-name="parameters"
         header-row-style="header-row" default-table-style="basic-table">
+        <actions>
+            <set field="quoteTypeId[]" value="OTHER_QUOTE"/>
+            <set field="quoteTypeId[]" value="PROPOSAL"/>
+        </actions>
         <auto-fields-entity entity-name="Quote" default-field-type="find"/>
         <field name="quoteId" title="${uiLabelMap.OrderOrderQuoteId}"></field>
         <field name="quoteTypeId" title="${uiLabelMap.OrderOrderQuoteTypeId}">
-            <drop-down allow-empty="true">
+            <check>
                 <entity-options entity-name="QuoteType" 
key-field-name="quoteTypeId"/>
-            </drop-down>
+            </check>
         </field>
         <field name="salesChannelEnumId" 
title="${uiLabelMap.OrderSalesChannel}">
             <drop-down allow-empty="true">
@@ -134,7 +138,7 @@ under the License.
                     <entity-constraint name="statusTypeId" 
value="QUOTE_STATUS"/>
                 </entity-options>
             </drop-down>
-        </field>        
+        </field>
         <field name="statusId" use-when="quote!=null" 
title="${uiLabelMap.CommonStatus}">
             <drop-down allow-empty="false" current="first-in-list" 
current-description="${currentStatus.description}">
                 <entity-options entity-name="StatusValidChangeToDetail" 
key-field-name="statusIdTo" description="${transitionName} (${description})">
@@ -545,7 +549,7 @@ under the License.
             <display-entity entity-name="TermType" description="${description} 
[${termTypeId}]" key-field-name="termTypeId"/>
         </field>
         <field name="quoteId"><hidden/></field>
-        
+
         <field name="uomId">
             <drop-down current-description="">
                 <entity-options entity-name="Uom" key-field-name="uomId"/>
diff --git a/applications/product/widget/catalog/ImageManagementForms.xml 
b/applications/product/widget/catalog/ImageManagementForms.xml
index 4285f3b007..568363c50c 100644
--- a/applications/product/widget/catalog/ImageManagementForms.xml
+++ b/applications/product/widget/catalog/ImageManagementForms.xml
@@ -62,13 +62,13 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
-    <form name="ImageGallery" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageGallery"> 
+
+    <form name="ImageGallery" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageGallery">
         <field name="productId" 
title="${uiLabelMap.ImageManagementChooseProductID}"><lookup 
target-form-name="LookupProduct"/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
-    <form name="ImageApprove" type="multi" title="" 
list-name="contentApprovalProductContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table" 
+
+    <form name="ImageApprove" type="multi" title="" 
list-name="contentApprovalProductContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table"
         use-row-submit="true" separate-columns="true" 
target="updateStatusImageManagement">
         <row-actions>
             <entity-and entity-name="ContentDataResourceView" 
list="contentDataResourceViews">
@@ -123,8 +123,8 @@ under the License.
         </field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
-    <grid name="ListPeopleApproved" title="" 
list-name="contentApprovalProductContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table" 
+
+    <grid name="ListPeopleApproved" title="" 
list-name="contentApprovalProductContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table"
         use-row-submit="true" separate-columns="true" target="">
         <row-actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResourceView">
@@ -162,8 +162,8 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
-    <form name="ListPeopleRejected" type="multi" title="" 
list-name="productContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table" 
+
+    <form name="ListPeopleRejected" type="multi" title="" 
list-name="productContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table"
         use-row-submit="true" separate-columns="true" 
target="addRejectedReasonImageManagement">
         <row-actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResourceView">
@@ -192,7 +192,7 @@ under the License.
         <field name="productId" title="${uiLabelMap.ProductProductName} 
[${uiLabelMap.ProductProductId}] - ${uiLabelMap.FormFieldTitle_categoryName}" 
entry-name="productId" position="1" use-when="${groovy:String 
prev=(String)previousItem.get(&quot;productId&quot;);return new 
Boolean(!(prev!=null&amp;&amp;prev.equals(productId)));}">
             <display-entity entity-name="Product" key-field-name="productId" 
description="${internalName} [${productId}] - ${productCategory.categoryName}" 
also-hidden="false"/>
         </field>
-        <field name="_rowSubmit" position="2" title=" " 
widget-style="hidden"><check all-checked="trueThumb"/></field>
+        <field name="_rowSubmit" position="2" title=" " 
widget-style="hidden"><check all-checked="true"/></field>
         <field name="drDataResourceName" position="2" 
title="${uiLabelMap.ImageManagementImageName}"><display/></field>
         <field name="contentId" position="2"><display/></field>
         <field name="dataResourceId" 
title="${uiLabelMap.ContentDataResourceId}" position="2"><display/></field>
@@ -212,8 +212,8 @@ under the License.
         </field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
-    <form name="ImageRejected" type="multi" title="" 
list-name="productContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table" 
+
+    <form name="ImageRejected" type="multi" title="" 
list-name="productContentAndInfos" odd-row-style="alternate-row" 
default-table-style="basic-table"
         use-row-submit="true" separate-columns="true" target="">
         <row-actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResourceView">
@@ -261,12 +261,12 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </form>
-    
-    <form name="ImageManage" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageManage"> 
+
+    <form name="ImageManage" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageManage">
         <field name="productId" 
title="${uiLabelMap.ImageManagementChooseProductID}"><lookup 
target-form-name="LookupProduct"/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
+
     <form name="ListImageManage" type="multi" title="" 
odd-row-style="alternate-row" default-table-style="basic-table" 
list-name="productContentAndInfoList"
         use-row-submit="true" separate-columns="true" 
target="setImageDetail?productId=${parameters.productId}">
         <actions>
@@ -306,7 +306,7 @@ under the License.
         <field name="_rowSubmit" title=" " widget-style="hidden"><check 
all-checked="true"/></field>
         <field name="drObjectInfo" title="${uiLabelMap.CommonImage}"><image 
style="cssImgThumb"/></field>
         <field name="action" use-when="${groovy: return context.drMimeTypeId 
== 'image/jpeg';}" title="${uiLabelMap.ImageManagementAction}" event="onChange" 
action="javascript:
-            
document.ListImageManage.action='checkAction?productId=${productId}&amp;contentId=${contentId}&amp;dataResourceId=${dataResourceId}';
 
+            
document.ListImageManage.action='checkAction?productId=${productId}&amp;contentId=${contentId}&amp;dataResourceId=${dataResourceId}';
             document.ListImageManage.submit();">
             <drop-down allow-empty="true">
                   <option key="frame" 
description="${uiLabelMap.ImageManagementFrame}"/>
@@ -359,8 +359,8 @@ under the License.
             <sort-field name="statusId"/>
         </sort-order>
     </form>
-    
-    <form name="ShowDefaultImage" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table"> 
+
+    <form name="ShowDefaultImage" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table">
         <actions>
             <entity-and entity-name="ProductContentAndInfo" 
list="productContentAndInfos">
                 <field-map field-name="productId" 
from-field="parameters.productId"/>
@@ -381,7 +381,7 @@ under the License.
         </actions>
         <field name="drObjectInfo" title=" "><image 
style="cssImgThumb"/></field>
     </form>
-    
+
     <form name="ImageFrames" type="single" title="" target="uploadFrame" 
header-row-style="header-row" default-table-style="basic-table" 
target-window="_self">
         <actions>
             <script 
location="component://product/src/main/groovy/org/apache/ofbiz/product/catalog/imagemanagement/ImageFrame.groovy"/>
@@ -394,7 +394,7 @@ under the License.
                 <field-map field-name="contentId" from-field="frameContentId"/>
                 <field-map field-name="drDataResourceId" 
from-field="frameDataResourceId"/>
             </entity-one>
-            
+
             <set field="frameURL" 
from-field="contentDataResource2.drObjectInfo"/>
             <set field="previewURL" 
from-field="contentFrameDataResource.drDataResourceName"/>
         </actions>
@@ -427,7 +427,7 @@ under the License.
         </field>
     </form>
 
-    <form name="ImageCropping" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="CropImage"> 
+    <form name="ImageCropping" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="CropImage">
         <actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResource">
                 <field-map field-name="contentId" 
from-field="parameters.contentId"/>
@@ -445,7 +445,7 @@ under the License.
         <field name="imageCropp" widget-area-style="cropbox" 
use-when="imageURL != null" title="${uiLabelMap.CommonImage}" ><image 
value="${imageURL}"/></field>
         <field name="imageCropp" use-when="imageURL == null" 
title="${uiLabelMap.CommonImage}" ><image value="/images/defaultImage.jpg" 
style="cssImgXLarge"/></field>
     </form>
-    
+
     <form name="ImageRotating" type="single" target="RotateImage" title="" 
header-row-style="header-row" default-table-style="basic-table">
         <actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResource">
@@ -475,7 +475,7 @@ under the License.
             </hyperlink>
         </field>
     </form>
-    
+
     <form name="ImageShare" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table">
         <actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResource">
@@ -508,7 +508,7 @@ under the License.
         <field name="html" title="${uiLabelMap.ImageManagementHTMLCode}" 
event="onClick" action="javascript:select();"><text/></field>
         <field name="htmlThumbnail" 
title="${uiLabelMap.ImageManagementHTMLThumbnail}" event="onClick" 
action="javascript:select();"><text/></field>
     </form>
-    
+
     <form name="ImageReplace" type="single" target="replaceImageToExistImage" 
title="" header-row-style="header-row" default-table-style="basic-table">
         <actions>
             <entity-one entity-name="ContentDataResourceView" 
value-field="contentDataResourceExist">
@@ -531,7 +531,7 @@ under the License.
         <field name="imageReplace" position="2" use-when="imageURLReplace != 
null&amp;&amp;imageURLExist != null" 
title="${uiLabelMap.ImageManagementImageToReplace}"><image 
value="${imageURLReplace}" style="cssImgXLarge"/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
+
     <grid name="ListImageUpload" title="" list-name="productContent" 
odd-row-style="alternate-row" default-table-style="basic-table" 
use-row-submit="true" separate-columns="true">
         <actions>
             <set field="dateNow" type="Timestamp" value="${groovy:import 
org.apache.ofbiz.base.util.UtilDateTime;UtilDateTime.nowTimestamp().getTime() - 
18000;}"/>
@@ -568,7 +568,7 @@ under the License.
             </hyperlink>
         </field>
     </grid>
-      
+
     <grid name="ListLookupImage" list-name="listIt" 
paginate-target="ListLookupImage" odd-row-style="alternate-row" 
default-table-style="basic-table hover-bar">
         <actions>
             <entity-condition entity-name="ProductContentAndInfo">
@@ -607,12 +607,12 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
-    <form name="ProductImageReplace" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageReplace"> 
+
+    <form name="ProductImageReplace" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="ListImageReplace">
         <field name="productId" 
title="${uiLabelMap.ImageManagementChooseProductID}"><lookup 
target-form-name="LookupProduct"/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
+
     <grid name="ListImageRecentlyApproved" title="" 
odd-row-style="alternate-row" default-table-style="basic-table" 
use-row-submit="true" separate-columns="true" target="">
         <actions>
             <entity-condition entity-name="ProductContentAndInfo">
@@ -656,7 +656,7 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
+
     <grid name="ListImageExist" title="" odd-row-style="alternate-row" 
default-table-style="basic-table" use-row-submit="true" separate-columns="true">
         <actions>
             <entity-condition entity-name="ProductContentAndInfo">
@@ -697,7 +697,7 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
+
     <grid name="ListImageReplace" title="" odd-row-style="alternate-row" 
default-table-style="basic-table" use-row-submit="true" separate-columns="true">
         <actions>
             <entity-condition entity-name="ProductContentAndInfo">
@@ -740,7 +740,7 @@ under the License.
             <hyperlink description="${uiLabelMap.CommonView}" 
target="${origContentDataResourceViews[0].drObjectInfo}" target-window="_blank" 
also-hidden="false" target-type="content"/>
         </field>
     </grid>
-    
+
     <grid name="ListLookupImageFrame" list-name="listIt" 
paginate-target="ListLookupImageFrame" odd-row-style="alternate-row" 
default-table-style="basic-table hover-bar">
         <actions>
             <entity-condition entity-name="ContentDataResourceView">
@@ -760,7 +760,7 @@ under the License.
             </hyperlink>
         </field>-->
     </grid>
-    
+
     <form name="ImageResize" type="single" title="" 
header-row-style="header-row" default-table-style="basic-table" 
target="resizeImages">
         <field name="resizeOption">
             <drop-down >
@@ -772,7 +772,7 @@ under the License.
         <field name="size" 
title="${uiLabelMap.ImageManagementImageWidth}"><text/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" 
widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
+
     <grid name="SizeListOfProduct" title="" odd-row-style="alternate-row" 
default-table-style="basic-table" use-row-submit="true" separate-columns="true">
         <actions>
             <entity-condition entity-name="ContentAssoc">
diff --git a/framework/widget/dtd/widget-form.xsd 
b/framework/widget/dtd/widget-form.xsd
index 188aeed46a..09b382faa4 100644
--- a/framework/widget/dtd/widget-form.xsd
+++ b/framework/widget/dtd/widget-form.xsd
@@ -877,7 +877,14 @@ under the License.
                 <xs:element ref="list-options" />
                 <xs:element ref="option" />
             </xs:choice>
-            <xs:attribute name="all-checked" type="xs:boolean"/>
+            <xs:attribute name="all-checked" type="xs:boolean">
+                <xs:annotation>
+                    <xs:documentation>
+                        None option is checked by default.
+                        You may check options by setting field names as in 
QuoteForms.xml#FindQuotes
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
         </xs:complexType>
     </xs:element>
     <xs:element name="container" substitutionGroup="AllFields">
diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
index 2b1ced540a..a06743b4c1 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java
@@ -1073,6 +1073,7 @@ public final class ModelFormField {
         public static final String ROW_SUBMIT_FIELD_NAME = "_rowSubmit";
         private final FlexibleStringExpander allChecked;
 
+
         private CheckField(CheckField original, ModelFormField modelFormField) 
{
             super(original, modelFormField);
             this.allChecked = original.allChecked;
diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
index fdf6f6a818..477101cbb7 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
@@ -530,6 +530,9 @@ public final class MacroFormRenderer implements 
FormStringRenderer {
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
         StringBuilder items = new StringBuilder();
+        List<String> checkedByDefault = 
context.containsKey(checkField.getModelFormField().getAttributeName())
+                ? 
StringUtil.toList(context.get(checkField.getModelFormField().getAttributeName()).toString())
+                : List.of();
         if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
             className = modelFormField.getWidgetStyle();
             if (modelFormField.shouldBeRed(context)) {
@@ -548,18 +551,28 @@ public final class MacroFormRenderer implements 
FormStringRenderer {
         }
 
         List<ModelFormField.OptionValue> allOptionValues = 
checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
+        //String stringCheckedByDefault = String.join(",", checkedByDefault);
         items.append("[");
         for (ModelFormField.OptionValue optionValue : allOptionValues) {
-            if (items.length() > 1) {
-                items.append(",");
-            }
-            items.append("{'value':'");
-            items.append(optionValue.getKey());
-            items.append("', 'description':'" + 
encode(optionValue.getDescription(), modelFormField, context));
-            if (UtilValidate.isNotEmpty(currentValueList) && 
currentValueList.contains(optionValue.getKey())) {
-                items.append("', 'checked':'" + Boolean.TRUE);
+            boolean checked;
+
+            if (UtilValidate.isNotEmpty(currentValueList)) {
+                checked = currentValueList.contains(optionValue.getKey());
+            } else {
+                if (UtilValidate.isNotEmpty(checkedByDefault)) {
+                    checked = checkedByDefault.contains(optionValue.getKey());
+                } else checked = allChecked;
             }
-            items.append("'}");
+            String data = String.format(
+                    "{'value':'%s', 'description':'%s', 'checked':'%s'}",
+                    optionValue.getKey(),
+                    encode(optionValue.getDescription(), modelFormField, 
context),
+                    checked);
+            items.append(data);
+            items.append(",");
+        }
+        if (items.length() > 0) {
+            items.deleteCharAt(items.length() - 1);
         }
         items.append("]");
         StringWriter sr = new StringWriter();
@@ -574,9 +587,7 @@ public final class MacroFormRenderer implements 
FormStringRenderer {
         sr.append(id);
         sr.append("\" conditionGroup=\"");
         sr.append(conditionGroup);
-        sr.append("\" allChecked=");
-        sr.append((allChecked != null && currentValueList == null ? 
Boolean.toString(allChecked) : "\"\""));
-        sr.append(" currentValue=\"");
+        sr.append("\" currentValue=\"");
         sr.append(currentValue);
         sr.append("\" name=\"");
         sr.append(name);
diff --git 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java
 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java
index ccef82b42b..e2d7801b72 100644
--- 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java
+++ 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRendererTest.java
@@ -26,11 +26,7 @@ import static org.hamcrest.Matchers.startsWith;
 
 import java.io.IOException;
 import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
@@ -282,7 +278,9 @@ public class MacroFormRendererTest {
     public void checkFieldMacroRendered(@Mocked ModelFormField.CheckField 
checkField) throws IOException {
         final List<ModelFormField.OptionValue> optionValues = ImmutableList.of(
                 new ModelFormField.OptionValue("KEY1", "DESC1"),
-                new ModelFormField.OptionValue("KEY2", "DESC2"));
+                new ModelFormField.OptionValue("KEY2", "DESC2"),
+                new ModelFormField.OptionValue("KEY3", "DESC3"),
+                new ModelFormField.OptionValue("KEY4", "DESC4"));
 
         new Expectations() {
             {
@@ -297,11 +295,46 @@ public class MacroFormRendererTest {
         macroFormRenderer.renderCheckField(appendable, ImmutableMap.of(), 
checkField);
         assertAndGetMacroString("renderCheckField", ImmutableMap.of(
                 "currentValue", "KEY2",
-                "items", ImmutableList.of("{'value':'KEY1', 
'description':'DESC1'}",
-                        "{'value':'KEY2', 'description':'DESC2', 
'checked':'true'}")));
-    }
+                "items", ImmutableList.of(
+                        "{'value':'KEY1', 'description':'DESC1', 
'checked':'false'}",
+                        "{'value':'KEY2', 'description':'DESC2', 
'checked':'true'}",
+                        "{'value':'KEY3', 'description':'DESC3', 
'checked':'false'}",
+                        "{'value':'KEY4', 'description':'DESC4', 
'checked':'false'}")));
+        new Expectations() {
+            {
+                modelFormField.getEntry(withNotNull());
+                result = "";
 
-    @Test
+                checkField.getModelFormField().getAttributeName();
+                result = "FieldName";
+
+
+            }
+        };
+
+        StringWriter writer = new StringWriter();
+        Map<String, Object> context = new HashMap<>();
+        LinkedList<String> fieldName = new LinkedList<>();
+        fieldName.add("KEY1");
+        fieldName.add("KEY3");
+        context.put("FieldName", fieldName);
+
+        try {
+            macroFormRenderer.renderCheckField(writer, context, checkField);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        String renderedString = writer.toString();
+        assertAndGetMacroString("renderCheckField", ImmutableMap.of(
+                "items", ImmutableList.of(
+                        "{'value':'KEY1', 'description':'DESC1', 
'checked':'true'}",
+                        "{'value':'KEY2', 'description':'DESC2', 
'checked':'false'}",
+                        "{'value':'KEY3', 'description':'DESC3', 
'checked':'true'}",
+                        "{'value':'KEY4', 'description':'DESC4', 
'checked':'false'}")));
+
+    }
+        @Test
     public void radioFieldMacroRendered(@Mocked ModelFormField.RadioField 
radioField) throws IOException {
         final List<ModelFormField.OptionValue> optionValues = ImmutableList.of(
                 new ModelFormField.OptionValue("KEY1", "DESC1"),
diff --git a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl 
b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
index e5ef6dd36b..8d5b2b8169 100644
--- a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
+++ b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
@@ -203,10 +203,10 @@ under the License.
   <#list items as item>
     <span <@renderClass className alert />><#rt/>
       <input <@renderDisabled disabled /> type="checkbox"<#if (item_index == 
0)> id="${id}"</#if><#rt/><#if tabindex?has_content> 
tabindex="${tabindex}"</#if><#rt/>
-        <#if allChecked?has_content && allChecked> checked="checked" <#elseif 
allChecked?has_content && !allChecked>
-        <#elseif item.checked?has_content && item.checked?boolean> 
checked="checked"</#if>
-        name="${name?default("")?html}" 
value="${item.value?default("")?html}"<#if event?has_content> 
${event}="${action}"</#if>/><#rt/>
-        ${item.description?default("")}
+        name="${name?default("")?html}" 
value="${item.value?default("")?html}"<#if event?has_content> 
${event}="${action}"</#if>
+        <#if allChecked?has_content && allChecked> checked="checked" </#if>
+        <#if item.checked?has_content && item.checked?boolean> 
checked="checked"</#if>/><#rt/>
+      ${item.description?default("")}
     </span>
   </#list>
 </#macro>

Reply via email to