Author: jleroux
Date: Mon May 28 14:37:44 2018 New Revision: 1832401 URL: http://svn.apache.org/viewvc?rev=1832401&view=rev Log: Improved: Empty header row should not render if list to render in file is empty (OFBIZ-7598) If list inside form doesn't contain data, then header row should not render from better UI perspective and proper message should be shown to user. Get to catalog/control/EditProductGoodIdentifications with eg productId=ID:GZ-1006 for a test Thanks: Suraj Modified: ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormRenderer.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormStringRenderer.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/fo/FoFormRenderer.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl Modified: ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd Mon May 28 14:37:44 2018 @@ -86,6 +86,7 @@ under the License. <xs:attribute name="style" type="xs:string" /> <xs:attribute name="focus-field-name" type="xs:string" /> <xs:attribute name="title" type="xs:string" /> + <xs:attribute name="empty-form-data-message" type="xs:string" /> <xs:attribute name="tooltip" type="xs:string" /> <xs:attribute name="list-name" type="xs:string"> <xs:annotation> @@ -327,6 +328,7 @@ under the License. <xs:attribute name="style" type="xs:string" /> <xs:attribute name="focus-field-name" type="xs:string" /> <xs:attribute name="title" type="xs:string" /> + <xs:attribute name="empty-form-data-message" type="xs:string" /> <xs:attribute name="tooltip" type="xs:string" /> <xs:attribute name="list-name" type="xs:string"> <xs:annotation> Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java Mon May 28 14:37:44 2018 @@ -147,7 +147,7 @@ public abstract class ModelForm extends private final String formWidgetAreaStyle; private final boolean groupColumns; private final String headerRowStyle; - private final boolean hideHeader; + private boolean hideHeader; private final String itemIndexSeparator; private final List<String> lastOrderFields; private final String listEntryName; @@ -184,6 +184,7 @@ public abstract class ModelForm extends private final String targetType; private final FlexibleStringExpander targetWindowExdr; private final String title; + private final String emptyFormDataMessage; private final String tooltip; private final String type; private final boolean useRowSubmit; @@ -241,6 +242,13 @@ public abstract class ModelForm extends title = parentModel.title; } this.title = title; + String emptyFormDataMessage = formElement.getAttribute("empty-form-data-message"); + if (emptyFormDataMessage.isEmpty() && parentModel != null) { + emptyFormDataMessage = parentModel.emptyFormDataMessage; + } else if (emptyFormDataMessage.isEmpty()) { + emptyFormDataMessage = UtilProperties.getMessage("CommonUiLabels", "CommonNoRecordFound", Locale.getDefault()); + } + this.emptyFormDataMessage = emptyFormDataMessage; String tooltip = formElement.getAttribute("tooltip"); if (tooltip.isEmpty() && parentModel != null) { tooltip = parentModel.tooltip; @@ -1007,6 +1015,9 @@ public abstract class ModelForm extends public boolean getHideHeader() { return this.hideHeader; } + public void setHideHeader(Boolean hideHeader) { + this.hideHeader = hideHeader; + } public String getItemIndexSeparator() { if (UtilValidate.isNotEmpty(this.itemIndexSeparator)) { @@ -1374,6 +1385,10 @@ public abstract class ModelForm extends return this.title; } + public String getEmptyFormDataMessage() { + return this.emptyFormDataMessage; + } + public String getTooltip() { return this.tooltip; } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormRenderer.java?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormRenderer.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormRenderer.java Mon May 28 14:37:44 2018 @@ -47,6 +47,7 @@ import org.apache.ofbiz.widget.model.Fie import org.apache.ofbiz.widget.model.ModelForm; import org.apache.ofbiz.widget.model.ModelForm.FieldGroup; import org.apache.ofbiz.widget.model.ModelForm.FieldGroupBase; +import org.apache.ofbiz.widget.model.ModelFormField.DisplayField; import org.apache.ofbiz.widget.model.ModelFormField; import org.apache.ofbiz.widget.model.ModelGrid; @@ -932,9 +933,12 @@ public class FormRenderer { formStringRenderer.renderFormatListWrapperOpen(writer, context, modelForm); int numOfColumns = 0; + this.checkFormDataAndSetHeader(context); // ===== render header row ===== if (!modelForm.getHideHeader()) { numOfColumns = this.renderHeaderRow(writer, context); + } else { + formStringRenderer.renderEmptyFormDataMessage(writer, context, modelForm); } // ===== render the item rows ===== @@ -958,9 +962,12 @@ public class FormRenderer { formStringRenderer.renderFormatListWrapperOpen(writer, context, modelForm); int numOfColumns = 0; + this.checkFormDataAndSetHeader(context); // ===== render header row ===== if (!modelForm.getHideHeader()) { numOfColumns = this.renderHeaderRow(writer, context); + } else { + formStringRenderer.renderEmptyFormDataMessage(writer, context, modelForm); } // ===== render the item rows ===== @@ -973,6 +980,31 @@ public class FormRenderer { } } + private void checkFormDataAndSetHeader(Map<String, Object> context) { + String lookupName = modelForm.getListName(); + Object obj = context.get(lookupName); + if (obj == null) { + if (Debug.verboseOn()) + Debug.logVerbose("No object for list or iterator name [" + lookupName + "] found, so not rendering rows.", module); + return; + } + // if list is empty, do not render rows + Iterator<?> iter = null; + if (obj instanceof Iterator<?>) { + iter = (Iterator<?>) obj; + } else if (obj instanceof List<?>) { + iter = ((List<?>) obj).listIterator(); + } + int itemIndex = -1; + Object item = null; + while ((item = safeNext(iter)) != null) { + itemIndex++; + break; + } + if (itemIndex < 0) { + modelForm.setHideHeader(true); + } + } private void renderSingleFormString(Appendable writer, Map<String, Object> context, int positions) throws IOException { Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormStringRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormStringRenderer.java?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormStringRenderer.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/FormStringRenderer.java Mon May 28 14:37:44 2018 @@ -99,4 +99,5 @@ public interface FormStringRenderer { public void renderContainerFindField(Appendable writer, Map<String, Object> context, ModelFormField.ContainerField containerField) throws IOException; public void renderFieldGroupOpen(Appendable writer, Map<String, Object> context, ModelForm.FieldGroup fieldGroup) throws IOException; public void renderFieldGroupClose(Appendable writer, Map<String, Object> context, ModelForm.FieldGroup fieldGroup) throws IOException; + public void renderEmptyFormDataMessage(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException; } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/fo/FoFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/fo/FoFormRenderer.java?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/fo/FoFormRenderer.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/fo/FoFormRenderer.java Mon May 28 14:37:44 2018 @@ -438,4 +438,7 @@ public class FoFormRenderer extends Html public void renderContainerFindField(Appendable writer, Map<String, Object> context, ContainerField containerField) throws IOException { } + public void renderEmptyFormDataMessage(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException { + // TODO + } } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java Mon May 28 14:37:44 2018 @@ -1543,6 +1543,14 @@ public final class MacroFormRenderer imp executeMacro(writer, sr.toString()); } + public void renderEmptyFormDataMessage(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException { + StringWriter sr = new StringWriter(); + sr.append("<@renderEmptyFormDataMessage"); + sr.append(" message=\""); + sr.append(modelForm.getEmptyFormDataMessage()); + sr.append("\" />"); + executeMacro(writer, sr.toString()); + } public void renderFormatListWrapperClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException { StringWriter sr = new StringWriter(); Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl?rev=1832401&r1=1832400&r2=1832401&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl (original) +++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl Mon May 28 14:37:44 2018 @@ -316,7 +316,9 @@ under the License. ${title}<#t/> </label><#t/> </#macro> - +<#macro renderEmptyFormDataMessage message> + <h3><#if message?has_content>${message}</#if></h3> +</#macro> <#macro renderSingleFormFieldTitle></#macro> <#macro renderFormOpen linkUrl formType name viewIndexField viewSizeField viewIndex viewSize targetWindow="" containerId="" containerStyle="" autocomplete="" useRowSubmit="" focusFieldName="" hasRequiredField=""> |
Free forum by Nabble | Edit this page |