I'm setting up some custom Netbeans Java template. When I'm using built-in function without argument such as ${name?lower_case}
, my template works fine. However, when I'm using a function with argument, I end up with an error (generated file is empty).
the so-called function is removing_ending
. I have a Test.java and I want to generate a TestView.java which relies on Test.java :
<#assign type = ${name?remove_ending("View")}>
<#if package?? && package != "">
package ${package};
</#if>
import com.company.project.AbstractClass;
public class ${name} extends AbstractClass<${type}>{
}
I wonder if I missed some import but the function is said to be built-in so I assumed it's available.
<#ftl>
at the top of the template without success type = "${name?remove_ending("View")}"
(double quote) or escaping quotes around the View
word didn't help neither EDIT & Solution
remove_ending
was simply not available. I used a name?substring(0, name?length - 4)
The correct syntax is <#assign type = name?remove_ending("View")>
. No ${}
is needed there.
Also, I don't know NetBeans, but there must be at least some log somewhere that tells you what the error was. (That it silently gives you empty output, without any error popup, is not very user friendly to say the least. Might worth filling a bug report at NetBeans.) If not, you can test your syntax on http://try.freemarker.org/ (though of course you won't have the same data-model, nor perhaps the same FreeMarker version, but in this case for example it tells you what the problem is).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.