2013-03-27 68 views
0

我有一个包含列表(列表中的所有值都是字符串)地图:为什么这个freemarker代码在列表中有一个逗号时失败?

["diameter":["1", "2", "3"]] 
["length":["2", "3", "4"]] 

我通过它在freemarker的迭代:

<#list product.getSortedVariantMap.keySet() as variantCode> 
    <#list product.getSortedVariantMap[variantCode] as variantValue> 

这工作得很好。但是,如果其中一个字符串包含这样一个逗号:

def returnValue = ["diameter":["3,5"]] 

我得到以下错误:

?size is unsupported for: freemarker.ext.beans.SimpleMethodModel 
The problematic instruction: 
---------- 
==> list product.getSortedVariantMap[variantCode] as variantValue [on line 200, column 41 in product.htm] 

我不知道该错误可能是什么,在字符串中的逗号不应该创建该错误。

+0

我认为问题可能是Freemarker如何包装从'product.getSortedVariantMap返回的bean '。您能否告诉我们在分析由'getSortedVariantMap'返回的类时Java反射会看到什么? – 2013-03-27 16:05:14

回答

1

它取决于FreeMarker配置,但product.getSortedVariantMap很可能返回方法本身,而不是它的返回值。你应该写product.sortedVariantMap。 (虽然我不明白为什么它不停止在product.getSortedVariantMap.keySet()之前,也许你的例子并不是什么运行?)

+1

'product.getSortedVariantMap'返回一张地图。 'product.getSortedVariantMap [variantCode]'返回一个方法 - 至少在某些情况下。这取决于'variantCode'的值,但如果没有原始海报提供更多细节,就不可能更具体。 – 2013-03-30 15:31:10