svn commit: r1139385 - /ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java

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

svn commit: r1139385 - /ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java

jleroux@apache.org
Author: jleroux
Date: Fri Jun 24 17:33:25 2011
New Revision: 1139385

URL: http://svn.apache.org/viewvc?rev=1139385&view=rev
Log:
A patch from Nicolas Malin <<Display dateTime field with input method time-dropdown not use context value to display hour and minutes>> https://issues.apache.org/jira/browse/OFBIZ-4319

If you define a dateTime field like that :

<field name="estimatedStartDate"><date-time input-method="time-dropdown" step="10"/></field>
and pass in context : estimatedStartDate = "2011-06-016 20:30:00"
when you edit the form, estimatedStartDate takes the good value 2011-06-016 on date, but takes nowTimestamps.hour for dropdown hour instead of 20 and nowTimestamps.minutes for dropdown minutes instead of 30

To test the patch :

    go to ofbiz example component with given date : "https://localhost:8443/example/control/FormWidgetExamples?field4=2001-01-01 02:21:000"
    the field 4 must have hour to 02 and minutes to 21

The patch also corrects multiple definition : sr.append("\" value=\"");
and removes unneeded escape at end line : if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";


Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=1139385&r1=1139384&r2=1139385&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Fri Jun 24 17:33:25 2011
@@ -507,10 +507,11 @@ public class MacroFormRenderer implement
                 alert = "true";
             }
         }
+        boolean useTimeDropDown = "time-dropdown".equals(dateTimeField.getInputMethod());
         String stepString = dateTimeField.getStep();
         int step = 1;
         StringBuilder timeValues = new StringBuilder();
-        if ( "time-dropdown".equals(dateTimeField.getInputMethod()) && UtilValidate.isNotEmpty(step)) {
+        if (useTimeDropDown && UtilValidate.isNotEmpty(step)) {
             try {
                 step = Integer.valueOf(stepString).intValue();
             } catch (IllegalArgumentException e) {
@@ -534,9 +535,9 @@ public class MacroFormRenderer implement
         String localizedInputTitle = "", localizedIconTitle = "";
 
         // whether the date field is short form, yyyy-mm-dd
-        boolean shortDateInput = ("date".equals(dateTimeField.getType()) || "time-dropdown".equals(dateTimeField.getInputMethod()) ? true : false);
+        boolean shortDateInput = ("date".equals(dateTimeField.getType()) || useTimeDropDown ? true : false);
 
-        if ("time-dropdown".equals(dateTimeField.getInputMethod())) {
+        if (useTimeDropDown) {
             name = UtilHttp.makeCompositeParam(paramName, "date");
         } else {
             name = paramName;
@@ -562,7 +563,14 @@ public class MacroFormRenderer implement
             }
         }
 
-        String value = modelFormField.getEntry(context, dateTimeField.getDefaultValue(context));
+        String contextValue = null;
+        //if time-dropdow desactive encodingOutput for found hour and minutes
+        boolean memEncodeOutput = modelFormField.getEncodeOutput();
+        if (useTimeDropDown) modelFormField.setEncodeOutput(false);
+        contextValue = modelFormField.getEntry(context, dateTimeField.getDefaultValue(context));
+        if (useTimeDropDown) modelFormField.setEncodeOutput(memEncodeOutput);
+
+        String value = contextValue;
         if (UtilValidate.isNotEmpty(value)) {
             if (value.length() > maxlength) {
                 value = value.substring(0, maxlength);
@@ -586,7 +594,7 @@ public class MacroFormRenderer implement
 
         if (!"time".equals(dateTimeField.getType())) {
             String tempParamName;
-            if ("time-dropdown".equals(dateTimeField.getInputMethod())) {
+            if (useTimeDropDown) {
                 tempParamName = UtilHttp.makeCompositeParam(paramName, "date");
             } else {
                 tempParamName = paramName;
@@ -597,7 +605,7 @@ public class MacroFormRenderer implement
 
         // if we have an input method of time-dropdown, then render two
         // dropdowns
-        if ("time-dropdown".equals(dateTimeField.getInputMethod())) {
+        if (useTimeDropDown) {
             className = modelFormField.getWidgetStyle();
             classString = (className != null ? className : "");
             isTwelveHour = "12".equals(dateTimeField.getClock());
@@ -605,7 +613,7 @@ public class MacroFormRenderer implement
             // set the Calendar to the default time of the form or now()
             Calendar cal = null;
             try {
-                Timestamp defaultTimestamp = Timestamp.valueOf(dateTimeField.getDefaultDateTimeString(context));
+                Timestamp defaultTimestamp = Timestamp.valueOf(contextValue);
                 cal = Calendar.getInstance();
                 cal.setTime(defaultTimestamp);
             } catch (IllegalArgumentException e) {
@@ -639,7 +647,7 @@ public class MacroFormRenderer implement
         //check for required field style on single forms
         if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
             String requiredStyle = modelFormField.getRequiredFieldStyle();
-            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";
             if (UtilValidate.isEmpty(className)) className = requiredStyle;
             else className = requiredStyle + " " + className;
         }
@@ -666,14 +674,10 @@ public class MacroFormRenderer implement
         sr.append(value);
         sr.append("\" title=\"");
         sr.append(localizedInputTitle);
-        sr.append("\" value=\"");
-        sr.append(value);
         sr.append("\" size=\"");
         sr.append(Integer.toString(size));
         sr.append("\" maxlength=\"");
         sr.append(Integer.toString(maxlength));
-        sr.append("\" value=\"");
-        sr.append(value);
         sr.append("\" step=\"");
         sr.append(Integer.toString(step));
         sr.append("\" timeValues=\"");