Simple bean without accessor are not found by Freemarker
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
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.
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.
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.
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 ?
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`.