FreeMarker Error : left-hand operand: Expected a hash, but this evaluated to a sequence

来源:互联网 发布:喝酒的好处知乎 编辑:程序博客网 时间:2024/06/05 18:22

FreeMarker Error : left-hand operand: Expected a hash, but this evaluated to a sequence

Ask Question
up vote2down votefavorite

When I loop through a list in freemarker like below, it works fine.

<#list cModel.products as product>

But when I'm tring to assign the size of the list to a variable like,

 <#assign totalProducts = cModel.products.getList()?size>

I'm getting an exception from free marker like below

left-hand operand: Expected a hash, but this evaluated to a sequence

Any suggestions?

shareimprove this question
 
 
What is the signature of Product.getList()? Post the Java. – Raedwald Jul 27 '14 at 7:43

1 Answer

activeoldestvotes
up vote5down voteaccepted

I Hope you've accessing it wrongly.

As per your example, the list name is product. So,

<#assign totalProducts = cModel.getProducts()?size>

Should return back the size of the products.

Hope it helps.

shareimprove this answer
 
 
Thanks for your reply. It resolved the issue. – javaAnto Jul 27 '14 at 13:25
1 
cModel.products?size is the nicer way of doing that. – ddekany Jul 27 '14 at 13:57 
0 0