[
https://issues.apache.org/jira/browse/FREEMARKER-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18034975#comment-18034975
]
John Pace edited comment on FREEMARKER-234 at 11/3/25 7:47 AM:
---------------------------------------------------------------
Thanks for explanation. Changing the function to
{code}public boolean isObsolete() {
return obsolete;
}{code}
worked. Now I can use myobject.obsolete in the template.
Please clarify in the documentation that isX() works with boolean, not with
Boolean. This distinction comes from the JavaBeans specification, but many
Freemarker users may not be familiar with that detail.
was (Author: JIRAUSER307027):
Thanks for explanation. Changing the function to
{code}public boolean isObsolete() {
return obsolete;
}{code}
worked. No I can use myobject.obsolete in the template.
Please clarify in the documentation that isX() works with boolean, not with
Boolean. This distinction comes from the JavaBeans specification, but many
Freemarker users may not be familiar with that detail.
> BeansWrapper does not expose Boolean "is" getters as properties
> ---------------------------------------------------------------
>
> Key: FREEMARKER-234
> URL: https://issues.apache.org/jira/browse/FREEMARKER-234
> Project: Apache Freemarker
> Issue Type: Bug
> Affects Versions: 2.3.34
> Environment: OpenJDK 17, Windows 10
> Reporter: John Pace
> Priority: Major
>
> According to the official
> [documentation|https://freemarker.apache.org/docs/pgui_misc_beanwrapper.html#beanswrapper_hash]:
> {quote}Every object will be wrapped into a TemplateHashModel that will expose
> JavaBeans properties and methods of the object. This way, you can use
> model.foo in the template to invoke obj.getFoo() or obj.isFoo() methods.
> {quote}
> However, this does not hold true for getters returning java.lang.Boolean.
> {code:java}
> public class MyObject {
> private Boolean obsolete = Boolean.TRUE;
> public Boolean isObsolete() {
> return obsolete;
> }
> }{code}
> {code:java}
> <!-- Works -->
> <#if myobject.isObsolete()>obsolete</#if>
> <!-- Does NOT work -->
> <#if myobject.obsolete>obsolete</#if> {code}
> {code:java}
> 19:55:46,241 ERROR f.runtime - Error executing FreeMarker template
> freemarker.core.InvalidReferenceException: The following has evaluated to
> null or missing:
> ==> myobject.obsolete [in template "templates/test.ftlh" at line 5, column
> 12]
> ----
> Tip: It's the step after the last dot that caused this error, not those
> before it.
> ----
> Tip: If the failing expression is known to legally refer to something that's
> sometimes null or missing, either specify a default value like
> myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the
> last step of the expression; to cover the whole expression, use parenthesis:
> (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)