Basic Freemarker Configuration

Freemarker as Templating Technology have evolved a lot from it’s traditional peers like velocity and other scripting languages.

I just wanted to post few lines of code which i generally use in My FreemarkerUtility. Rename the download to .rar
FreeMarkerEngine

Few of Common Problem we Face with Freemarker are in using map
One of the Error is like

Expected hash. evaluated instead to freemarker.ext.beans.SimpleMethodModel

This has been overcomed by following piece of code


// Specify how templates will see the data-model. This is an advanced
// topic...
// but just use this:
cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
BeansWrapper bw = (BeansWrapper)cfg.getObjectWrapper();
bw.setSimpleMapWrapper(true);
bw.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
cfg.setObjectWrapper(bw);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s