ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jler...@apache.org
Subject svn commit: r1665544 - in /ofbiz/branches/release12.04/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/form/MacroFormRenderer.java src/org/ofbiz/widget/form/ModelFormField.java
Date Tue, 10 Mar 2015 13:37:35 GMT
Author: jleroux
Date: Tue Mar 10 13:37:35 2015
New Revision: 1665544

URL: http://svn.apache.org/r1665544
Log:
Fixes <<"Lookup fields break when used with a form having skip-start="true">>
https://issues.apache.org/jira/browse/OFBIZ-6139

We neglected this aspect so far, adding a "form-name" attribute to the lookup element fixes
it. You then need also to set the correct id-name value on field element.

Modified:
    ofbiz/branches/release12.04/framework/widget/dtd/widget-form.xsd
    ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java

Modified: ofbiz/branches/release12.04/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/widget/dtd/widget-form.xsd?rev=1665544&r1=1665543&r2=1665544&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/branches/release12.04/framework/widget/dtd/widget-form.xsd Tue Mar 10 13:37:35 2015
@@ -681,6 +681,7 @@ under the License.
             <xs:sequence>
                 <xs:element ref="in-place-editor" minOccurs="0" maxOccurs="1"/>
             </xs:sequence>
+                        <xs:enumeration value="date-fix" />
             <xs:attributeGroup ref="attlist.display"/>
         </xs:complexType>
     </xs:element>
@@ -1139,6 +1140,13 @@ under the License.
         </xs:attribute>
         <xs:attribute name="confirmation-message" type="xs:string"><xs:annotation><xs:documentation>The
message displayed in confirmation box</xs:documentation></xs:annotation></xs:attribute>
     </xs:attributeGroup>
+            <xs:attribute type="xs:string" name="form-name">
+                <xs:annotation>
+                    <xs:documentation>
+                        The name of the parent form, needed when using skip-start="true"
along with correct id-name value on field
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
     <xs:element name="text" substitutionGroup="AllFields">
         <xs:complexType>
             <xs:sequence>

Modified: ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=1665544&r1=1665543&r2=1665544&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
(original)
+++ ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
Tue Mar 10 13:37:35 2015
@@ -50,6 +50,7 @@ import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.base.util.template.FreeMarkerWorker;
 import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.util.EntityUtilProperties;
 import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.webapp.taglib.ContentUrlTag;
 import org.ofbiz.widget.ModelWidget;
@@ -667,6 +668,11 @@ public class MacroFormRenderer implement
                 formattedMask = "9999-99-99 99:99:99";
             }
         }
+        Delegator delegator = (Delegator) request.getAttribute("delegator");
+        String timeFormat = "";
+        if (UtilValidate.isNotEmpty(delegator)) {
+            timeFormat = EntityUtilProperties.getPropertyValue("general", "displayTimeFormat",
delegator);
+        }
         StringWriter sr = new StringWriter();
         sr.append("<@renderDateTimeField ");
         sr.append("name=\"");
@@ -731,6 +737,8 @@ public class MacroFormRenderer implement
         sr.append(formName);
         sr.append("\" mask=\"");
         sr.append(formattedMask);
+        sr.append("\" timeFormat=\"");
+        sr.append(timeFormat);
         sr.append("\" />");
         executeMacro(writer, sr.toString());
         this.addAsterisks(writer, context, modelFormField);
@@ -1602,6 +1610,10 @@ public class MacroFormRenderer implement
                 oddRowStyle = FlexibleStringExpander.expandString(modelForm.getOddRowStyle(),
context);
             }
         }
+        
+        Delegator delegator = (Delegator)context.get("delegator");
+        String defaultDateFormat = EntityUtilProperties.getPropertyValue("general.properties",
"displayDateFindFormat", "yy-mm-dd", delegator);
+
         StringWriter sr = new StringWriter();
         sr.append("<@renderFormatItemRowOpen ");
         sr.append(" formName=\"");
@@ -1954,7 +1966,7 @@ public class MacroFormRenderer implement
         int size = 25;
         int maxlength = 30;
         String dateType =  dateFindField.getType();
-        if ("date".equals(dateType)) {
+        if ("date".equals(dateType) || "date-fix".equals(dateType)) {
             size = maxlength = 10;
             if (uiLabelMap != null) {
                 localizedInputTitle = uiLabelMap.get("CommonFormatDate");
@@ -2050,6 +2062,8 @@ public class MacroFormRenderer implement
         sr.append(opUpThruDay);
         sr.append("\" opIsEmpty=\"");
         sr.append(opIsEmpty);
+        sr.append("\" defaultDateFormat=\"");
+        sr.append(defaultDateFormat);
         sr.append("\" />");
         executeMacro(writer, sr.toString());
 
@@ -2112,7 +2126,10 @@ public class MacroFormRenderer implement
 
         // add lookup pop-up button
         String descriptionFieldName = lookupField.getDescriptionFieldName();
-        String formName = modelFormField.getModelForm().getCurrentFormName(context);
+        String formName = lookupField.getParentFormName();
+        if (UtilValidate.isEmpty(formName)) {
+            formName = modelFormField.getModelForm().getCurrentFormName(context);
+        }
         StringBuilder targetParameterIter = new StringBuilder();
         StringBuilder imgSrc = new StringBuilder();
         // FIXME: refactor using the StringUtils methods

Modified: ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=1665544&r1=1665543&r2=1665544&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
(original)
+++ ofbiz/branches/release12.04/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
Tue Mar 10 13:37:35 2015
@@ -63,6 +63,7 @@ import org.ofbiz.entity.model.ModelEntit
 import org.ofbiz.entity.model.ModelField;
 import org.ofbiz.entity.model.ModelReader;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityUtilProperties;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.ModelParam;
@@ -1993,19 +1994,14 @@ public class ModelFormField {
                     throw new IllegalArgumentException(errMsg);
                 }
             } else if ("date".equals(this.type) && retVal.length() > 10) {
-                Locale locale = (Locale) context.get("locale");
-                if (locale == null) {
-                    locale = Locale.getDefault();
-                }
-
                 StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp();
                 Timestamp timestamp = null;
                 try {
                     timestamp = stringToTimestamp.convert(retVal);
                     Date date = new Date(timestamp.getTime());
-
-                    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT,
locale);
-                    retVal = dateFormatter.format(date);
+                    Delegator delegator = (Delegator)context.get("delegator");
+                    String displayDateFormat = EntityUtilProperties.getPropertyValue("general.properties",
"displayDateFormat", "dd-MM-yyyy", delegator);
+                    retVal = UtilDateTime.toDateString(date, displayDateFormat);
                 }
                 catch (ConversionException e) {
                     String errMsg = "Error formatting date using default instead [" + retVal
+ "]: " + e.toString();
@@ -2015,23 +2011,14 @@ public class ModelFormField {
                 }
 
             } else if ("date-time".equals(this.type) && retVal.length() > 16)
{
-                Locale locale = (Locale) context.get("locale");
-                TimeZone timeZone = (TimeZone) context.get("timeZone");
-                if (locale == null) {
-                    locale = Locale.getDefault();
-                }
-                if (timeZone == null) {
-                    timeZone = TimeZone.getDefault();
-                }
-
                 StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp();
                 Timestamp timestamp = null;
                 try {
                     timestamp = stringToTimestamp.convert(retVal);
                     Date date = new Date(timestamp.getTime());
-
-                    DateFormat dateFormatter = UtilDateTime.toDateTimeFormat(null, timeZone,
locale);
-                    retVal = dateFormatter.format(date);
+                    Delegator delegator = (Delegator)context.get("delegator");
+                    String displayDateTimeFormat = EntityUtilProperties.getPropertyValue("general.properties",
"displayDateTimeFormat", "dd-MM-yyyy HH:mm:ss.SSS", delegator);
+                    retVal = UtilDateTime.toDateString(date, displayDateTimeFormat);
                 }
                 catch (ConversionException e) {
                     String errMsg = "Error formatting date/time using default instead ["
+ retVal + "]: " + e.toString();
@@ -3516,6 +3503,7 @@ public class ModelFormField {
 
     public static class LookupField extends TextField {
         protected FlexibleStringExpander formName;
+        protected String parentFormName;
         protected String descriptionFieldName;
         protected String targetParameter;
         protected String lookupPresentation;
@@ -3528,6 +3516,7 @@ public class ModelFormField {
         public LookupField(Element element, ModelFormField modelFormField) {
             super(element, modelFormField);
             this.formName = FlexibleStringExpander.getInstance(element.getAttribute("target-form-name"));
+            this.parentFormName = element.getAttribute("form-name");
             this.descriptionFieldName = element.getAttribute("description-field-name");
             this.targetParameter = element.getAttribute("target-parameter");
             this.lookupPresentation = element.getAttribute("presentation");
@@ -3556,6 +3545,10 @@ public class ModelFormField {
             return this.formName.expandString(context);
         }
 
+        public String getParentFormName() {
+            return this.parentFormName;
+        }
+
         public List<String> getTargetParameterList() {
             List<String> paramList = FastList.newInstance();
             if (UtilValidate.isNotEmpty(this.targetParameter)) {



Mime
View raw message