Hi Rishi,

Thanks for your time

Yes the urlEncodeArgs() convert the Map very well, but the list present in the map isn't convert to string as OFbiz converter wait it.

If I follow your suggest, and use StringUtil.toMap instead of StringUtil.toList in the CollectionConverter.java to convert, I will generate an IllegalArgumentException.

To solve my problem I make the choice to extend StringToList convert to support two notation with [] as UEL and {} as generate by toString() function.


Index: framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java
===================================================================
--- framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java (révision 1332225) +++ framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java (copie de travail)
@@ -146,7 +146,8 @@

         @Override
public List<String> convert(String obj) throws ConversionException {
-            if (obj.startsWith("[") && obj.endsWith("]")) {
+            if ((obj.startsWith("[") && obj.endsWith("]"))
+                    || (obj.startsWith("{") && obj.endsWith("}"))) {
                 return StringUtil.toList(obj);
             } else {
                 return super.convert(obj);
Index: framework/base/src/org/ofbiz/base/util/StringUtil.java
===================================================================
--- framework/base/src/org/ofbiz/base/util/StringUtil.java (révision 1332225) +++ framework/base/src/org/ofbiz/base/util/StringUtil.java (copie de travail)
@@ -396,7 +396,8 @@
      */
     public static List<String> toList(String s) {
         List<String> newList = FastList.newInstance();
-        if (s.startsWith("[") && s.endsWith("]")) {
+        if ((s.startsWith("[") && s.endsWith("]"))
+                || (s.startsWith("{") && s.endsWith("}"))) {
             s = s.substring(1, s.length() - 1);
             String[] entries = s.split("\\,\\s");
             for (String entry: entries) {

Nicolas

 Le 01/05/2012 16:44, Rishi Solanki a écrit :
Nicolas,
Please have a look into the method specified urlEncodeArgs() of UtilHttp
class. It takes the Map as argument and if while conversion it gives you '{
}' then it is fine. You just need to use map converter instead of list
converter.
It should works perfectly then. Assuming you are talking about the
StringUtil.toList method, and I'm redirecting to you to use
StringUtil.toMap method.

HTH!

--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com


On Fri, Apr 27, 2012 at 8:42 PM, Nicolas Malin<
[email protected]>  wrote:

Hi, I would like to explain a little problem with OFBiz convert where I
don't found a clean solution.

To start : a search form with a multiple drop-down  that call a perform
service with an attribute List
the form :
<field name="**partyClassificationGroupId">
<drop-down allow-multiple="true" size="20" allow-empty="true">...

the service :
<service ...>
<attribute name="**partyClassificationGroupId" type="List" mode="IN"
optional="true"/>  ...

When I execute the research, the service get the list but the paginate
lost it.
On the queryString the list is encoded like this : "{element1, element2}",
but the service use Converter class to load it and search : "[element1,
element2]".

The queryString is encoded by UtilHttp.urlEncodeArgs :
if (value instanceof String) {
valueStr = (String) value;
} else {
valueStr = value.toString();
}
which generate "{element1, element2}"

And converter StringToList :
if (obj.startsWith("[")&&  obj.endsWith("]")) {
return StringUtil.toList(obj);

Other point, converter ListToString use also value.toString();

Do you think it is better to extend StringToList to support "{}" or to
correct encode and convert process to use "[]" ?

Nicolas


-- Nicolas MALIN Consultant Tél : 06.17.66.40.06 Site projet :
http://www.neogia.org/ ------- Société LibrenBerry Tél : 02.48.02.56.12
Site : http://www.librenberry.net/



--
Nicolas MALIN
Consultant
Tél : 06.17.66.40.06
Site projet : http://www.neogia.org/
-------
Société LibrenBerry
Tél : 02.48.02.56.12
Site : http://www.librenberry.net/

Reply via email to