svn commit: r1037146 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/form/ModelForm.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1037146 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/form/ModelForm.java

jonesde
Author: jonesde
Date: Sat Nov 20 09:32:30 2010
New Revision: 1037146

URL: http://svn.apache.org/viewvc?rev=1037146&view=rev
Log:
Added new group-columns attribute to form element to not group input/other columns if not desired, defaults to true which is the old/original behavior

Modified:
    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=1037146&r1=1037145&r2=1037146&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Sat Nov 20 09:32:30 2010
@@ -155,6 +155,14 @@ under the License.
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="group-columns" default="true">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
         <xs:attribute type="xs:integer" name="view-size">
             <xs:annotation><xs:documentation>The number of items to display per page</xs:documentation></xs:annotation>
         </xs:attribute>

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=1037146&r1=1037145&r2=1037146&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Sat Nov 20 09:32:30 2010
@@ -112,6 +112,7 @@ public class ModelForm extends ModelWidg
     protected String paginateTargetAnchor;
     protected String paginateStyle;
     protected boolean separateColumns = false;
+    protected boolean groupColumns = true;
     protected boolean useRowSubmit = false;
     protected FlexibleStringExpander targetWindowExdr;
     protected String defaultRequiredFieldStyle;
@@ -285,6 +286,7 @@ public class ModelForm extends ModelWidg
                 this.defaultTooltipStyle = parent.defaultTooltipStyle;
                 this.itemIndexSeparator = parent.itemIndexSeparator;
                 this.separateColumns = parent.separateColumns;
+                this.groupColumns = parent.groupColumns;
                 this.targetType = parent.targetType;
                 this.defaultMapName = parent.defaultMapName;
                 this.targetWindowExdr = parent.targetWindowExdr;
@@ -460,6 +462,11 @@ public class ModelForm extends ModelWidg
             if (sepColumns != null && sepColumns.equalsIgnoreCase("true"))
                 separateColumns = true;
         }
+        if (formElement.hasAttribute("group-columns")) {
+            String groupColumnsStr = formElement.getAttribute("group-columns");
+            if (groupColumnsStr != null && groupColumnsStr.equalsIgnoreCase("false"))
+                groupColumns = false;
+        }
         if (formElement.hasAttribute("use-row-submit")) {
             String rowSubmit = formElement.getAttribute("use-row-submit");
             if (rowSubmit != null && rowSubmit.equalsIgnoreCase("true"))
@@ -1236,7 +1243,8 @@ public class ModelForm extends ModelWidg
 
             Map<String, List<ModelFormField>> fieldRow = UtilMisc.toMap("displayBefore", innerDisplayHyperlinkFieldsBegin,
                                                    "inputFields", innerFormFields,
-                                                   "displayAfter", innerDisplayHyperlinkFieldsEnd);
+                                                   "displayAfter", innerDisplayHyperlinkFieldsEnd,
+                                                   "mainFieldList", mainFieldList);
             fieldRowsByPosition.add(fieldRow);
         }
         // ===========================
@@ -1246,6 +1254,7 @@ public class ModelForm extends ModelWidg
             List<ModelFormField> innerDisplayHyperlinkFieldsBegin = listsMap.get("displayBefore");
             List<ModelFormField> innerFormFields = listsMap.get("inputFields");
             List<ModelFormField> innerDisplayHyperlinkFieldsEnd = listsMap.get("displayAfter");
+            List<ModelFormField> mainFieldList = listsMap.get("mainFieldList");
 
             int numOfCells = innerDisplayHyperlinkFieldsBegin.size() +
                              innerDisplayHyperlinkFieldsEnd.size() +
@@ -1257,57 +1266,81 @@ public class ModelForm extends ModelWidg
 
             if (numOfCells > 0) {
                 formStringRenderer.renderFormatHeaderRowOpen(writer, context, this);
-                Iterator<ModelFormField> innerDisplayHyperlinkFieldsBeginIt = innerDisplayHyperlinkFieldsBegin.iterator();
-                while (innerDisplayHyperlinkFieldsBeginIt.hasNext()) {
-                    ModelFormField modelFormField = innerDisplayHyperlinkFieldsBeginIt.next();
-                    // span columns only if this is the last column in the row (not just in this first list)
-                    if (innerDisplayHyperlinkFieldsBeginIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size()) {
-                        formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, 1);
-                    } else {
-                        formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, numOfColumnsToSpan);
+                
+                if (this.groupColumns) {
+                    Iterator<ModelFormField> innerDisplayHyperlinkFieldsBeginIt = innerDisplayHyperlinkFieldsBegin.iterator();
+                    while (innerDisplayHyperlinkFieldsBeginIt.hasNext()) {
+                        ModelFormField modelFormField = innerDisplayHyperlinkFieldsBeginIt.next();
+                        // span columns only if this is the last column in the row (not just in this first list)
+                        if (innerDisplayHyperlinkFieldsBeginIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size()) {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, 1);
+                        } else {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, numOfColumnsToSpan);
+                        }
+                        formStringRenderer.renderFieldTitle(writer, context, modelFormField);
+                        formStringRenderer.renderFormatHeaderRowCellClose(writer, context, this, modelFormField);
                     }
-                    formStringRenderer.renderFieldTitle(writer, context, modelFormField);
-                    formStringRenderer.renderFormatHeaderRowCellClose(writer, context, this, modelFormField);
-                }
-                if (innerFormFields.size() > 0) {
-                    // TODO: manage colspan
-                    formStringRenderer.renderFormatHeaderRowFormCellOpen(writer, context, this);
-                    Iterator<ModelFormField> innerFormFieldsIt = innerFormFields.iterator();
-                    while (innerFormFieldsIt.hasNext()) {
-                        ModelFormField modelFormField = innerFormFieldsIt.next();
+                    if (innerFormFields.size() > 0) {
+                        // TODO: manage colspan
+                        formStringRenderer.renderFormatHeaderRowFormCellOpen(writer, context, this);
+                        Iterator<ModelFormField> innerFormFieldsIt = innerFormFields.iterator();
+                        while (innerFormFieldsIt.hasNext()) {
+                            ModelFormField modelFormField = innerFormFieldsIt.next();
 
-                        if (separateColumns || modelFormField.getSeparateColumn()) {
-                            formStringRenderer.renderFormatItemRowCellOpen(writer, context, this, modelFormField, 1);
-                        }
+                            if (separateColumns || modelFormField.getSeparateColumn()) {
+                                formStringRenderer.renderFormatItemRowCellOpen(writer, context, this, modelFormField, 1);
+                            }
 
-                        // render title (unless this is a submit or a reset field)
-                        formStringRenderer.renderFieldTitle(writer, context, modelFormField);
+                            // render title (unless this is a submit or a reset field)
+                            formStringRenderer.renderFieldTitle(writer, context, modelFormField);
 
-                        if (separateColumns || modelFormField.getSeparateColumn()) {
-                            formStringRenderer.renderFormatItemRowCellClose(writer, context, this, modelFormField);
-                        }
+                            if (separateColumns || modelFormField.getSeparateColumn()) {
+                                formStringRenderer.renderFormatItemRowCellClose(writer, context, this, modelFormField);
+                            }
 
-                        if (innerFormFieldsIt.hasNext()) {
-                            // TODO: determine somehow if this is the last one... how?
-                           if (!separateColumns && !modelFormField.getSeparateColumn()) {
-                                formStringRenderer.renderFormatHeaderRowFormCellTitleSeparator(writer, context, this, modelFormField, false);
-                           }
+                            if (innerFormFieldsIt.hasNext()) {
+                                // TODO: determine somehow if this is the last one... how?
+                               if (!separateColumns && !modelFormField.getSeparateColumn()) {
+                                    formStringRenderer.renderFormatHeaderRowFormCellTitleSeparator(writer, context, this, modelFormField, false);
+                               }
+                            }
                         }
+                        formStringRenderer.renderFormatHeaderRowFormCellClose(writer, context, this);
                     }
-                    formStringRenderer.renderFormatHeaderRowFormCellClose(writer, context, this);
-                }
-                Iterator<ModelFormField> innerDisplayHyperlinkFieldsEndIt = innerDisplayHyperlinkFieldsEnd.iterator();
-                while (innerDisplayHyperlinkFieldsEndIt.hasNext()) {
-                    ModelFormField modelFormField = innerDisplayHyperlinkFieldsEndIt.next();
-                    // span columns only if this is the last column in the row (not just in this first list)
-                    if (innerDisplayHyperlinkFieldsEndIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsEnd.size()) {
-                        formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, 1);
-                    } else {
-                        formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, numOfColumnsToSpan);
+                    Iterator<ModelFormField> innerDisplayHyperlinkFieldsEndIt = innerDisplayHyperlinkFieldsEnd.iterator();
+                    while (innerDisplayHyperlinkFieldsEndIt.hasNext()) {
+                        ModelFormField modelFormField = innerDisplayHyperlinkFieldsEndIt.next();
+                        // span columns only if this is the last column in the row (not just in this first list)
+                        if (innerDisplayHyperlinkFieldsEndIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsEnd.size()) {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, 1);
+                        } else {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, numOfColumnsToSpan);
+                        }
+                        formStringRenderer.renderFieldTitle(writer, context, modelFormField);
+                        formStringRenderer.renderFormatHeaderRowCellClose(writer, context, this, modelFormField);
+                    }
+                } else {
+                    Iterator<ModelFormField> mainFieldListIter = mainFieldList.iterator();
+                    while (mainFieldListIter.hasNext()) {
+                        ModelFormField modelFormField = mainFieldListIter.next();
+                        
+                        // don't do any header for hidden or ignored fields
+                        ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
+                        if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
+                            continue;
+                        }
+
+                        // span columns only if this is the last column in the row (not just in this first list)
+                        if (mainFieldListIter.hasNext() || numOfCells > mainFieldList.size()) {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, 1);
+                        } else {
+                            formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, this, modelFormField, numOfColumnsToSpan);
+                        }
+                        formStringRenderer.renderFieldTitle(writer, context, modelFormField);
+                        formStringRenderer.renderFormatHeaderRowCellClose(writer, context, this, modelFormField);
                     }
-                    formStringRenderer.renderFieldTitle(writer, context, modelFormField);
-                    formStringRenderer.renderFormatHeaderRowCellClose(writer, context, this, modelFormField);
                 }
+                
                 formStringRenderer.renderFormatHeaderRowClose(writer, context, this);
             }
         }
@@ -1589,7 +1622,9 @@ public class ModelForm extends ModelWidg
                     // are now rendered: this will create a visual representation
                     // of one row (for the current position).
                     if (innerDisplayHyperlinkFieldsBegin.size() > 0 || innerFormFields.size() > 0 || innerDisplayHyperlinkFieldsEnd.size() > 0) {
-                        this.renderItemRow(writer, localContext, formStringRenderer, formPerItem, hiddenIgnoredFieldList, innerDisplayHyperlinkFieldsBegin, innerFormFields, innerDisplayHyperlinkFieldsEnd, currentPosition, numOfColumns);
+                        this.renderItemRow(writer, localContext, formStringRenderer, formPerItem, hiddenIgnoredFieldList,
+                                innerDisplayHyperlinkFieldsBegin, innerFormFields, innerDisplayHyperlinkFieldsEnd, fieldListByPosition,
+                                currentPosition, numOfColumns);
                     }
                 } // iteration on positions
             } // iteration on items
@@ -1615,7 +1650,10 @@ public class ModelForm extends ModelWidg
     // The fields in the three lists, usually created in the preprocessing phase
     // of the renderItemRows method are rendered: this will create a visual representation
     // of one row (corresponding to one position).
-    public void renderItemRow(Appendable writer, Map<String, Object> localContext, FormStringRenderer formStringRenderer, boolean formPerItem, List<ModelFormField> hiddenIgnoredFieldList, List<ModelFormField> innerDisplayHyperlinkFieldsBegin, List<ModelFormField> innerFormFields, List<ModelFormField> innerDisplayHyperlinkFieldsEnd, int position, int numOfColumns) throws IOException {
+    public void renderItemRow(Appendable writer, Map<String, Object> localContext, FormStringRenderer formStringRenderer,
+            boolean formPerItem, List<ModelFormField> hiddenIgnoredFieldList, List<ModelFormField> innerDisplayHyperlinkFieldsBegin,
+            List<ModelFormField> innerFormFields, List<ModelFormField> innerDisplayHyperlinkFieldsEnd, List<ModelFormField> mainFieldList,
+            int position, int numOfColumns) throws IOException {
         int numOfCells = innerDisplayHyperlinkFieldsBegin.size() +
                          innerDisplayHyperlinkFieldsEnd.size() +
                          (innerFormFields.size() > 0? 1: 0);
@@ -1638,86 +1676,111 @@ public class ModelForm extends ModelWidg
             }
         }
 
-        // do the first part of display and hyperlink fields
-        Iterator<ModelFormField> innerDisplayHyperlinkFieldIter = innerDisplayHyperlinkFieldsBegin.iterator();
-        while (innerDisplayHyperlinkFieldIter.hasNext()) {
-            boolean cellOpen = false;
-            ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
-            // span columns only if this is the last column in the row (not just in this first list)
-            if( fieldCount.get(modelFormField.getName()) < 2 ){
-                if ((innerDisplayHyperlinkFieldIter.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size())) {
-                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
-                } else {
-                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+        if (this.groupColumns) {
+            // do the first part of display and hyperlink fields
+            Iterator<ModelFormField> innerDisplayHyperlinkFieldIter = innerDisplayHyperlinkFieldsBegin.iterator();
+            while (innerDisplayHyperlinkFieldIter.hasNext()) {
+                boolean cellOpen = false;
+                ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
+                // span columns only if this is the last column in the row (not just in this first list)
+                if( fieldCount.get(modelFormField.getName()) < 2 ){
+                    if ((innerDisplayHyperlinkFieldIter.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size())) {
+                        formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+                    } else {
+                        formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+                    }
+                    cellOpen = true;
                 }
-                cellOpen = true;
-            }
-            if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
-                    if(( fieldCount.get(modelFormField.getName()) > 1 )){
-                        if ((innerDisplayHyperlinkFieldIter.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size())) {
-                            formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
-                        } else {
-                            formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+                if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
+                        if(( fieldCount.get(modelFormField.getName()) > 1 )){
+                            if ((innerDisplayHyperlinkFieldIter.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size())) {
+                                formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+                            } else {
+                                formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+                            }
+                            cellOpen = true;
                         }
-                        cellOpen = true;
-                    }
-                modelFormField.renderFieldString(writer, localContext, formStringRenderer);
-            }
-            if (cellOpen) {
-                formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
+                    modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+                }
+                if (cellOpen) {
+                    formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
+                }
             }
-        }
 
-        // The form cell is rendered only if there is at least an input field
-        if (innerFormFields.size() > 0) {
-            // render the "form" cell
-            formStringRenderer.renderFormatItemRowFormCellOpen(writer, localContext, this); // TODO: colspan
-
-            if (formPerItem) {
-                formStringRenderer.renderFormOpen(writer, localContext, this);
-            }
-
-            // do all of the hidden fields...
-            this.renderHiddenIgnoredFields(writer, localContext, formStringRenderer, hiddenIgnoredFieldList);
-
-            Iterator<ModelFormField> innerFormFieldIter = innerFormFields.iterator();
-            while (innerFormFieldIter.hasNext()) {
-                ModelFormField modelFormField = innerFormFieldIter.next();
-                if (separateColumns || modelFormField.getSeparateColumn()) {
-                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+            // The form cell is rendered only if there is at least an input field
+            if (innerFormFields.size() > 0) {
+                // render the "form" cell
+                formStringRenderer.renderFormatItemRowFormCellOpen(writer, localContext, this); // TODO: colspan
+
+                if (formPerItem) {
+                    formStringRenderer.renderFormOpen(writer, localContext, this);
                 }
-                // render field widget
-                if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
-                    modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+
+                // do all of the hidden fields...
+                this.renderHiddenIgnoredFields(writer, localContext, formStringRenderer, hiddenIgnoredFieldList);
+
+                Iterator<ModelFormField> innerFormFieldIter = innerFormFields.iterator();
+                while (innerFormFieldIter.hasNext()) {
+                    ModelFormField modelFormField = innerFormFieldIter.next();
+                    if (separateColumns || modelFormField.getSeparateColumn()) {
+                        formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+                    }
+                    // render field widget
+                    if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
+                        modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+                    }
+
+                    if (separateColumns || modelFormField.getSeparateColumn()) {
+                        formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
+                    }
                 }
 
-                if (separateColumns || modelFormField.getSeparateColumn()) {
-                    formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
+                if (formPerItem) {
+                    formStringRenderer.renderFormClose(writer, localContext, this);
                 }
+
+                formStringRenderer.renderFormatItemRowFormCellClose(writer, localContext, this);
             }
 
-            if (formPerItem) {
-                formStringRenderer.renderFormClose(writer, localContext, this);
+            // render the rest of the display/hyperlink fields
+            innerDisplayHyperlinkFieldIter = innerDisplayHyperlinkFieldsEnd.iterator();
+            while (innerDisplayHyperlinkFieldIter.hasNext()) {
+                ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
+                // span columns only if this is the last column in the row
+                if (innerDisplayHyperlinkFieldIter.hasNext()) {
+                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+                } else {
+                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+                }
+                if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
+                    modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+                }
+                formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
             }
+        } else {
+            Iterator<ModelFormField> mainFieldIter = mainFieldList.iterator();
+            while (mainFieldIter.hasNext()) {
+                ModelFormField modelFormField = mainFieldIter.next();
 
-            formStringRenderer.renderFormatItemRowFormCellClose(writer, localContext, this);
-        }
+                // don't do any header for hidden or ignored fields
+                ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
+                if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
+                    continue;
+                }
 
-        // render the rest of the display/hyperlink fields
-        innerDisplayHyperlinkFieldIter = innerDisplayHyperlinkFieldsEnd.iterator();
-        while (innerDisplayHyperlinkFieldIter.hasNext()) {
-            ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
-            // span columns only if this is the last column in the row
-            if (innerDisplayHyperlinkFieldIter.hasNext()) {
-                formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
-            } else {
-                formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
-            }
-            if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
-                modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+                // span columns only if this is the last column in the row
+                if (mainFieldIter.hasNext()) {
+                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, 1);
+                } else {
+                    formStringRenderer.renderFormatItemRowCellOpen(writer, localContext, this, modelFormField, numOfColumnsToSpan);
+                }
+                if ((!"list".equals(this.getType()) && !"multi".equals(this.getType())) || modelFormField.shouldUse(localContext)) {
+                    modelFormField.renderFieldString(writer, localContext, formStringRenderer);
+                }
+                formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
             }
-            formStringRenderer.renderFormatItemRowCellClose(writer, localContext, this, modelFormField);
         }
+        
 
         // render row formatting close
         formStringRenderer.renderFormatItemRowClose(writer, localContext, this);