gist JS

Tuesday, April 11, 2006

Freemarker Booleans in Beans

Note to self, making model beans that you want to use in Freemarker? Make sure them boolean's are java.lang.Boolean (in the docs) and change your getters from isMyBool() to getMyBool() (not in the docs), otherwise it's headscratching time trying to figure out why it can't find your junk.

Expression command.myBooleanis undefined on line 262, column 6 in WEB-INF/freemarker/verify.ftl.
The problematic instruction:
==> if command.myBoolean [on line 262, column 1 in WEB-INF/freemarker/verifyStudy.ftl]

Java backtrace for programmers:
freemarker.core.InvalidReferenceException: Expression command.myBoolean is undefined on line 262, column 6 in WEB-INF/freemarker/verify.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.Expression.isTrue(Expression.java:145)

Most important though is to get on junit testing your freemarker views. Getting this all set was such a lovely vindication of sorts for me. Nice tests all the way from the DB to the web? Without this testing the above would've been misery. Now? I just feel pretty much invincible.


Miroslav Genov said...


I'm encountering the same problem when I try to do the same thing with a string property value. Here is my code:

<#-- @ftlvariable name="rc" type="server.web.MyRequestContext" -->

Note that macro tags are removed, cause blog doesn't want to accept them in the comment

public String getPrincipal() {
return "TEST";

Do you have an idea where is the problem?

Thanks in advance.

Ryan P said...

Though this is over 4 years old, this is exactly the problem I was having.

Thank you for posting this!

Anonymous said...

same problem, thanks =)

Barnaby Relph said...

Thanks! I hit exactly the same thing and your post saved me a lot of head scratching!