Menu

#383 Simple bean without accessor are not found by Freemarker

undecided
closed-invalid
nobody
Parsing (33)
5
2014-06-15
2013-03-16
jmcollin92
No

Hello,

This simple bean :
public class HtmlTemplateInvoiceContext {

public String title=null; // Optional : the title of the Html that will be generated
public String footerMessage=null; // Optional : the footerMessage. If absent, no footer will be generated
public String htmlCompanyTitle=""; // The company title in html style
public Address myAddress=new Address(); // My address
public String myLandlinePhoneNumber=null; // Optional : landline phone number
public String myMobilePhoneNumber=null ; // Optional : mobile phone number
}
put in a context is not usable by FM. If there is no getter, the attributes are not found.
I consider this is a unfortunate.

Discussion

  • Dániel Dékány

    If it has no getters, then those are not JavaBean properties. (This isn't up to FreeMarker, this is what JavaBean spec says.) But, FreeMarker can expose public fields too, only by default this option is off. You have call theObjetWrapperYouAreUsing.setExposeFields(true) where you configure FreeMarker. (Maybe it should be on by default...)

    I will mark this as invalid as it's not a bug.

     
  • Dániel Dékány

    • status: open --> pending-invalid
     
  • jmcollin92

    jmcollin92 - 2013-03-18
    • status: pending-invalid --> open-invalid
     
  • jmcollin92

    jmcollin92 - 2013-03-18

    OK. Thanks for your explanation.
    > Maybe it should be on by default...
    I think so, but it is no important if we can expose field.

     
  • jmcollin92

    jmcollin92 - 2013-03-18

    Hum, it is finally not so evident. I use the standard config :
    _fmConfig.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);

    How can I change the setExposedField which such a creation of wrapper ?

     
  • Dániel Dékány

    By calling said setter, you could... But since ObjectWrapper.BEANS_WRAPPER is a shared object, I wouldn't do that. Actually, I wouldn't use ObjectWrapper.BEANS_WRAPPER at all. Use a `new BeansWrapper()`, and while you are there, you can also set `setSimpleMapWrapper(true)`, unless you like getting method names when calling `someMap?keys`.

     
  • Dániel Dékány

    • status: open-invalid --> closed-invalid
    • Group: --> undecided
     

Log in to post a comment.