Menu

#119 a bug?

undecided
open
nobody
None
5
2015-04-02
2015-04-01
No

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?

Discussion

  • Dániel Dékány

    The good question is rather that why the first one works. It's clearly not required by the JavaBeans spec, and for Map-s get(Object) is handled specially anyway. So that's some historical heritage. Also note that it only works with String argument (not Object). The static object model doesn't implement the same strange feature. (More importantly, it also doesn't implement calling model.getX() for model.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
  • Dániel Dékány

    Ticket moved from /p/freemarker/bugs/425/

     

Log in to post a comment.