Hyunah kim
Hyunah kim

Reputation: 1

Freemarker "Expected a number or boolean, but this has evaluated to a method+sequence"

I have a Boolean in my FreeMarker template "isApprove" and trying to assign a value to a variable juste like that

    <#list data.myList as unitObj>
      {
         ... ,
         "isApprove" : ${unitObj.isApprove?c}
      }
      <#if unitObj_has_next>,</#if>
    </#list>

but I get an exception from FreeMarker like below

freemarker.core.UnexpectedTypeException: For "?c" left-hand operand: Expected a number or boolean, but this has evaluated to a method+sequence

I checked the official documentation of FreeMarker they mentioned for the boolean you have to add "?c" but it doesn't work for me, is there something I'm missing ?

Upvotes: 0

Views: 1732

Answers (1)

ddekany
ddekany

Reputation: 31112

Depends on how does the Java API of unitObj look like. Also, your problem is not related to ?c, it's simply that you don't get a boolean value before it.

If you have boolean isApprove() there, then you should write unitObj.approvate, to get the boolean value (and after that you can put ?c of course).

If you have Boolean isApprove(), then that's not a valid Java Bean property getter, and it should be renamed to Boolean getApprove() in Java. If that can't be fixed, then you can refer to the isApprove method itself, but then it also has to be called to get the boolean value: unitObj.isApprove().

Upvotes: 1

Related Questions