public class Model{
public Object get(Object obj){
return "abc";
}
}
configuration.setSharedVariable("model", new Model);
${model.xxxx}//abc
but
public class Model{
public static Object get(Object obj){
return "abc";
}
}
BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
TemplateHashModel staticModels = wrapper.getStaticModels();
configuration.setSharedVariable("model", staticModels.get("com.Model"));
${model.xxxx}// wrong????
why?
The good question is rather that why the first one works. It's clearly not required by the JavaBeans spec, and for
Map
-sget(Object)
is handled specially anyway. So that's some historical heritage. Also note that it only works withString
argument (notObject
). The static object model doesn't implement the same strange feature. (More importantly, it also doesn't implement callingmodel.getX()
formodel.x
, since static methods can't be JavaBean property reader methods.)So I think that it's a missing feature at best. But I don't see why this feature exists elsewhere at all. What's your use case?
Last edit: Dániel Dékány 2015-04-01
Ticket moved from /p/freemarker/bugs/425/