freemarker.template.TemplateModelException when using Stripes LayoutRenderTag with Freemarker 2.3.18

Description

We managed Stripes LayoutRenderTag to work with the latest version of Freemarker 2.3.x. without the need of a dynamic attribute to be set. Freemarker throws some curious exception when using the LayoutRenderTag without a dynamic attribute.

It's because Stripes overrides the Tagwriter instance of Freemarker in the getContext() method of the LayoutRenderTag class within the doStartTag() method. That's a problem because Freemarks checks if the Writer (Tagwriter) before the Tag is called is the same like after Tag processing.

If you set a dynamic attribute on the layout-render tag the getContext() method in LayoutRenderTag is called within the setDynamicAttribute() method and before the doStartTag() method is invoked. If the LayoutContext is initialized before the doStartTag() method is invoked all goes fine.

So i override the setPageContext() method within the LayoutRenderTag class and call the getContext() method before anything else is invoked.

LayoutRenderTag.java

Here is the layout used in my tests:

layout.ftl with the layout-definition

test.ftl with the layout-render

There some other really annoying problems when using Stripes and Freemarker we have managed to go away.

This execption is raised because of the SKIP_PAGE return value in LayoutDefinitionTag class in the doEndTag() method.
I change the return value in EVAL_PAGE to prevent the output of the WARN message.

and

in the LayoutWriter class the flush() method throw an unhandled exception NullPointerException because the expected Writer is null. The root cause is unknown, but i added a null-check to prevent this WARN message too.

After that all pages renders fine, i can use Freemarker templates with layout tags of Stripes.

Environment

Freemarker 2.3.18
Stripes 1.5.6

Assignee

Unassigned

Reporter

xhaggi

Labels

None

Components

Affects versions

Priority

Major
Configure