svn commit: r1839729 - in /ofbiz/ofbiz-framework/trunk: framework/webtools/widget/ framework/widget/dtd/ framework/widget/src/main/java/org/apache/ofbiz/widget/model/ framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ framework/widget/src...

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

svn commit: r1839729 - in /ofbiz/ofbiz-framework/trunk: framework/webtools/widget/ framework/widget/dtd/ framework/widget/src/main/java/org/apache/ofbiz/widget/model/ framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ framework/widget/src...

surajk
Author: surajk
Date: Fri Aug 31 06:33:07 2018
New Revision: 1839729

URL: http://svn.apache.org/viewvc?rev=1839729&view=rev
Log:
Improved: Empty header row should not render if list to render in file is empty.
(OFBIZ-7598)
Thanks everyone for your inputs and suggestions.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml
    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/CsvFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/FoFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/TextFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XlsFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XmlFormMacroLibrary.ftl

Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml Fri Aug 31 06:33:07 2018
@@ -199,9 +199,9 @@ under the License.
             </condition>
             <actions>
                 <property-map resource="WebtoolsErrorUiLabels" map-name="uiLabelMap"/>
-                <script location="component://webtools/groovyScripts/entity/FindGeneric.groovy"/>
                 <property-map resource="CommonUiLabels" map-name="uiLabelMap"/>
                 <property-map resource="WebtoolsUiLabels" map-name="uiLabelMap"/>
+                <script location="component://webtools/groovyScripts/entity/FindGeneric.groovy"/>
                 <set field="title" value="${uiLabelMap.WebtoolsFindValues} ${uiLabelMap.WebtoolsForEntity}: ${entityName}"/>
                 <set field="commonDisplaying" from-field="uiLabelMap.CommonDisplaying"/>
                 <set field="tabButtonItem" value="entitymaint"/>

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=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-form.xsd Fri Aug 31 06:33:07 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" default="${uiLabelMap.CommonNoRecordFound}"/>
             <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" default="${uiLabelMap.CommonNoRecordFound}"/>
             <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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 2018
@@ -184,6 +184,7 @@ public abstract class ModelForm extends
     private final String targetType;
     private final FlexibleStringExpander targetWindowExdr;
     private final String title;
+    private final FlexibleStringExpander emptyFormDataMessage;
     private final String tooltip;
     private final String type;
     private final boolean useRowSubmit;
@@ -241,6 +242,11 @@ public abstract class ModelForm extends
             title = parentModel.title;
         }
         this.title = title;
+        FlexibleStringExpander emptyFormDataMessage = FlexibleStringExpander.getInstance(formElement.getAttribute("empty-form-data-message"));
+        if (emptyFormDataMessage.isEmpty() && parentModel != null) {
+            emptyFormDataMessage = parentModel.emptyFormDataMessage;
+        }
+        this.emptyFormDataMessage = emptyFormDataMessage;
         String tooltip = formElement.getAttribute("tooltip");
         if (tooltip.isEmpty() && parentModel != null) {
             tooltip = parentModel.tooltip;
@@ -1374,6 +1380,10 @@ public abstract class ModelForm extends
         return this.title;
     }
 
+    public String getEmptyFormDataMessage(Map<String, Object> context) {
+        return this.emptyFormDataMessage.expandString(context);
+    }
+
     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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 2018
@@ -51,6 +51,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;
 
@@ -921,11 +922,14 @@ public class FormRenderer {
         formStringRenderer.renderFormatListWrapperOpen(writer, context, modelForm);
 
         int numOfColumns = 0;
+        boolean containsData = this.checkFormData(context);
         // ===== render header row =====
-        if (!modelForm.getHideHeader()) {
+        if (!modelForm.getHideHeader() && containsData) {
             numOfColumns = this.renderHeaderRow(writer, context);
         }
-
+        if (!containsData){
+            formStringRenderer.renderEmptyFormDataMessage(writer, context, modelForm);
+        }
         // ===== render the item rows =====
         this.renderItemRows(writer, context, formStringRenderer, true, numOfColumns);
 
@@ -947,11 +951,14 @@ public class FormRenderer {
         formStringRenderer.renderFormatListWrapperOpen(writer, context, modelForm);
 
         int numOfColumns = 0;
+        boolean containsData = this.checkFormData(context);
         // ===== render header row =====
-        if (!modelForm.getHideHeader()) {
+        if (!modelForm.getHideHeader() && containsData) {
             numOfColumns = this.renderHeaderRow(writer, context);
         }
-
+        if (!containsData){
+            formStringRenderer.renderEmptyFormDataMessage(writer, context, modelForm);
+        }
         // ===== render the item rows =====
         this.renderItemRows(writer, context, formStringRenderer, false, numOfColumns);
 
@@ -1192,6 +1199,42 @@ public class FormRenderer {
         }
 
     }
+    private boolean checkFormData(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 true;
+        }
+        // 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;
+        if (iter instanceof EntityListIterator) {
+            EntityListIterator eli = (EntityListIterator) iter;
+            try {
+                if(eli.getResultsSizeAfterPartialList() > 0){
+                    itemIndex++;
+                }
+            } catch (GenericEntityException gee) {
+                Debug.logError(gee,module);
+            }
+        } else {
+            while (iter.hasNext()) {
+                itemIndex++;
+                break;
+            }
+        }
+        if (itemIndex < 0) {
+            return false;
+        }
+        return true;
+    }
 
     private static <X> X safeNext(Iterator<X> iterator) {
         try {

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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 2018
@@ -1546,6 +1546,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(context));
+        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/CsvFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/CsvFormMacroLibrary.ftl?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/CsvFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/CsvFormMacroLibrary.ftl Fri Aug 31 06:33:07 2018
@@ -51,6 +51,7 @@ under the License.
 <#macro renderIgnoredField></#macro>
 
 <#macro renderFieldTitle style title id="" fieldHelpText="" for=""><@renderField title />,</#macro>
+<#macro renderEmptyFormDataMessage message></#macro>
 <#macro renderSingleFormFieldTitle></#macro>
 
 <#macro renderFormOpen linkUrl formType targetWindow containerId containerStyle autocomplete name viewIndexField viewSizeField viewIndex viewSize useRowSubmit focusFieldName hasRequiredField></#macro>

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/FoFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/FoFormMacroLibrary.ftl?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/FoFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/FoFormMacroLibrary.ftl Fri Aug 31 06:33:07 2018
@@ -77,6 +77,7 @@ under the License.
 <#macro renderIgnoredField><!--ignore--></#macro>
 
 <#macro renderFieldTitle style title id fieldHelpText="" for=""><fo:block <@getFoStyle style/>>${title?default("")?replace("&nbsp;", " ")}</fo:block></#macro>
+<#macro renderEmptyFormDataMessage message></#macro>
 <#macro renderSingleFormFieldTitle><!--title form--></#macro>
 
 <#macro renderFormOpen linkUrl formType targetWindow containerId containerStyle autocomplete name viewIndexField viewSizeField viewIndex viewSize useRowSubmit focusFieldName hasRequiredField></#macro>

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=1839729&r1=1839728&r2=1839729&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 Fri Aug 31 06:33:07 2018
@@ -317,7 +317,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="">

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/TextFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/TextFormMacroLibrary.ftl?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/TextFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/TextFormMacroLibrary.ftl Fri Aug 31 06:33:07 2018
@@ -51,6 +51,7 @@ under the License.
 <#macro renderIgnoredField></#macro>
 
 <#macro renderFieldTitle style title id fieldHelpText="" for=""><@renderField title /></#macro>
+<#macro renderEmptyFormDataMessage message></#macro>
 <#macro renderSingleFormFieldTitle></#macro>
 
 <#macro renderFormOpen linkUrl formType targetWindow containerId containerStyle autocomplete name viewIndexField viewSizeField viewIndex viewSize useRowSubmit focusFieldName hasRequiredField></#macro>

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XlsFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XlsFormMacroLibrary.ftl?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XlsFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XlsFormMacroLibrary.ftl Fri Aug 31 06:33:07 2018
@@ -55,6 +55,7 @@ under the License.
 <#macro renderIgnoredField></#macro>
 
 <#macro renderFieldTitle style title id fieldHelpText="" for=""><@renderItemField title "txf" style/></#macro>
+<#macro renderEmptyFormDataMessage message></#macro>
 
 <#macro renderSingleFormFieldTitle></#macro>
 

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XmlFormMacroLibrary.ftl?rev=1839729&r1=1839728&r2=1839729&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XmlFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/XmlFormMacroLibrary.ftl Fri Aug 31 06:33:07 2018
@@ -59,6 +59,7 @@ under the License.
 <#macro renderIgnoredField></#macro>
 
 <#macro renderFieldTitle style title id fieldHelpText="" for=""></#macro>
+<#macro renderEmptyFormDataMessage message></#macro>
 <#macro renderSingleFormFieldTitle></#macro>
 
 <#macro renderFormOpen linkUrl formType targetWindow containerId containerStyle autocomplete name viewIndexField viewSizeField viewIndex viewSize useRowSubmit focusFieldName hasRequiredField></#macro>