You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2015/05/28 14:58:31 UTC
svn commit: r1682234 -
/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java
Author: mbrohl
Date: Thu May 28 12:58:31 2015
New Revision: 1682234
URL: http://svn.apache.org/r1682234
Log:
Applied patch from jira issue OFBIZ-6414: drop-down widget field with allow-multiple="true" does not display current value.
ModelFormField.getEntry returns the string representation of the value corresponding to the field in either the context map or parameters map but when the value is returned as a list [X, Y, Z], the opening and closing brackets are encoded [X, Y, Z]
This prevents the FormRenderer (atleast MacroFormRenderer) from detecting a list object from the string and converting it back to a list
eg - currentValueList = StringUtil.toList(currentValue).
The solution detects a collection value and handles the proper encoding.
Thanks Gareth Carter for reporting the issue and providing the patch.
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java?rev=1682234&r1=1682233&r2=1682234&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java Thu May 28 12:58:31 2015
@@ -24,9 +24,11 @@ import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -267,6 +269,8 @@ public class ModelFormField {
if (timeZone == null)
timeZone = TimeZone.getDefault();
+ UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
+
String returnValue;
// if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used
@@ -346,6 +350,23 @@ public class ModelFormField {
} else if (retVal instanceof java.util.Date) {
DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null);
return df.format((java.util.Date) retVal);
+ } else if (retVal instanceof Collection) {
+ Collection<Object> col = UtilGenerics.checkCollection(retVal);
+ Iterator<Object> iter = col.iterator();
+ ArrayList<Object> newCol = new ArrayList<Object>(col.size());
+ while (iter.hasNext()) {
+ Object item = iter.next();
+ if (item == null) {
+ continue;
+ }
+ if (simpleEncoder != null) {
+ newCol.add(simpleEncoder.encode(item.toString()));
+ }
+ else {
+ newCol.add(item.toString());
+ }
+ }
+ return newCol.toString();
} else {
returnValue = retVal.toString();
}
@@ -355,7 +376,6 @@ public class ModelFormField {
}
if (this.getEncodeOutput() && returnValue != null) {
- UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
if (simpleEncoder != null)
returnValue = simpleEncoder.encode(returnValue);
}