freemarker 不支援 boolean 型別 :Templates do break when an attribute contains a boolean value
阿新 • • 發佈:2019-02-09
If in a template <td>${attribute.value}</td> is used, and value is boolean, the following exception is thrown:
freemarker.core.NonStringException: Error on line 19, column 3 in description.ftl
Expecting a string, date or number here, Expression a.value is instead a freemarker.ext.beans.BooleanModel
- quote: "..Unlike numbers, booleans has no commonly accepted format, not even a
common format within the same page. Like when you show on a HTML page.."
"...The common way of formatting a boolean is like ${washable?string("yes", "no")},
${caching?string("Enabled", "Disabled")}, ${heating?string("on", "off")}, etc..."
- By the other hand, the Features used in the unit test for FeatureTemplate contained no boolean properties. Adding a boolean property to the test data still didn't make the error to show up, as the template used uses <td>${attribute.value.toString()}</td>. Changing the template to use <td>${attribute.value}</td> exposes the error.
freemarker.core.NonStringException: Error on line 19, column 3 in description.ftl
Expecting a string, date or number here, Expression a.value is instead a freemarker.ext.beans.BooleanModel
common format within the same page. Like when you show on a HTML page.."
"...The common way of formatting a boolean is like ${washable?string("yes", "no")},
${caching?string("Enabled", "Disabled")}, ${heating?string("on", "off")}, etc..."
- By the other hand, the Features used in the unit test for FeatureTemplate contained no boolean properties. Adding a boolean property to the test data still didn't make the error to show up, as the template used uses <td>${attribute.value.toString()}</td>. Changing the template to use <td>${attribute.value}</td> exposes the error.