Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

freemarker

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?

like image 440
javaAnto Avatar asked Jul 27 '14 02:07

javaAnto


2 Answers

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.

like image 187
Charles Avatar answered Nov 03 '22 01:11

Charles


Having json:

{
    "domain": {
        "kingdom": []
    },
}

We create a variable and assign the size of the kingdom list to it.

<#assign kingdomLen = domain.kingdom?size>   
<#if kingdomLen > 0 >
    We have kingdoms!
</#if>

And that is how we use it in an if-example.

like image 30
Reneta Avatar answered Nov 03 '22 00:11

Reneta