Just an observation, not commenting on this commit specifically:

The conversion to String should use the ObjectType.simpleTypeConvert(...) method - there are a lot of conversions being missed in this code.

-Adrian

On 5/13/2010 1:32 AM, jone...@apache.org wrote:
Author: jonesde
Date: Thu May 13 08:32:09 2010
New Revision: 943843

URL: http://svn.apache.org/viewvc?rev=943843&view=rev
Log:
Made widget link parameter treatment more consistent; before if you specified a 
paramaeter name without a from-field then it wouldn't convert the object 
according to locale; now it does the same thing no matter where the object 
comes from (ie explicit from-field or implied by the parameter name); this 
fixes a timeZone inconsistency that causes links with time/timestamp parameters 
to not work

Modified:
     ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java?rev=943843&r1=943842&r2=943843&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Thu May 
13 08:32:09 2010
@@ -30,6 +30,7 @@ import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

+import org.ofbiz.base.util.Debug;
  import org.ofbiz.base.util.StringUtil;
  import org.ofbiz.base.util.UtilDateTime;
  import org.ofbiz.base.util.UtilGenerics;
@@ -316,44 +317,41 @@ public class WidgetWorker {
          public String getValue(Map<String, Object>  context) {
              if (this.value != null) {
                  return this.value.expandString(context);
-            } else if (this.fromField != null&&  this.fromField.get(context) 
!= null) {
-                Object retVal = this.fromField.get(context);
+            }
+
+            Object retVal = null;
+            if (this.fromField != null&&  this.fromField.get(context) != null) 
{
+                retVal = this.fromField.get(context);
+            } else {
+                retVal = context.get(this.name);
+            }
+
+            if (retVal != null) {
+                TimeZone timeZone = (TimeZone) context.get("timeZone");
+                if (timeZone == null) timeZone = TimeZone.getDefault();

-                if (retVal != null) {
-                    TimeZone timeZone = (TimeZone) context.get("timeZone");
-                    if (timeZone == null) timeZone = TimeZone.getDefault();
-
-                    String returnValue = null;
-                    // format string based on the user's time zone (not locale 
because these are parameters)
-                    if (retVal instanceof Double || retVal instanceof Float || 
retVal instanceof BigDecimal) {
-                        returnValue = retVal.toString();
-                    } else if (retVal instanceof java.sql.Date) {
-                        DateFormat df = 
UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null);
-                        returnValue = df.format((java.util.Date) retVal);
-                    } else if (retVal instanceof java.sql.Time) {
-                        DateFormat df = 
UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null);
-                        returnValue = df.format((java.util.Date) retVal);
-                    } else if (retVal instanceof java.sql.Timestamp) {
-                        DateFormat df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
-                        returnValue = df.format((java.util.Date) retVal);
-                    } else if (retVal instanceof java.util.Date) {
-                        DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd 
hh:mm:ss z yyyy", timeZone, null);
-                        returnValue = df.format((java.util.Date) retVal);
-                    } else {
-                        returnValue = retVal.toString();
-                    }
-                    return returnValue;
+                String returnValue = null;
+                // format string based on the user's time zone (not locale 
because these are parameters)
+                if (retVal instanceof Double || retVal instanceof Float || 
retVal instanceof BigDecimal) {
+                    returnValue = retVal.toString();
+                } else if (retVal instanceof java.sql.Date) {
+                    DateFormat df = 
UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null);
+                    returnValue = df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.sql.Time) {
+                    DateFormat df = 
UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null);
+                    returnValue = df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.sql.Timestamp) {
+                    DateFormat df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
+                    returnValue = df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.util.Date) {
+                    DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd 
hh:mm:ss z yyyy", timeZone, null);
+                    returnValue = df.format((java.util.Date) retVal);
                  } else {
-                    return null;
+                    returnValue = retVal.toString();
                  }
+                return returnValue;
              } else {
-                // as a last chance try finding a context field with the key 
of the name field
-                Object obj = context.get(this.name);
-                if (obj != null) {
-                    return obj.toString();
-                } else {
-                    return null;
-                }
+                return null;
              }
          }
      }



Reply via email to