[
https://issues.apache.org/struts/browse/WW-1808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40934
]
Jasper Rosenberg commented on WW-1808:
--------------------------------------
That is an excellent point. Perhaps instead of checking getWriteCompleted()
(or in addition to it), in FreemarkerResult, we can just check the exception
handler on the configuration:
if (configuration.getTemplateExceptionHandler() ==
TemplateExceptionHandler.RETHROW_HANDLER) {
CharArrayWriter charArrayWriter = new CharArrayWriter();
template.process(model, charArrayWriter);
charArrayWriter.flush();
charArrayWriter.writeTo(writer);
} else {
template.process(model, writer);
}
This handles this most common case, but we might still want the optional
parameter in case someone wants to use their own TemplateExceptionHandler that
also requires the same behavior for FreemarkerResult.
> Support Freemarker template_exception_handler=rethrow
> -----------------------------------------------------
>
> Key: WW-1808
> URL: https://issues.apache.org/struts/browse/WW-1808
> Project: Struts 2
> Issue Type: Improvement
> Components: Views
> Affects Versions: 2.0.6
> Reporter: Jasper Rosenberg
> Priority: Minor
> Fix For: 2.1.0
>
>
> If you set in freemarker.properties, the property:
> template_exception_handler=rethrow
> Then you do not want the FreemarkerResult to output to the Writer unless you
> know the template processed cleanly (so you can handle the exception and go
> to a nice error page rather than being stuck with half rendered template
> output).
> My suggestion is to add a new parameter to FreemarkerResult, something like
> "writeCompleted" which defaults to false and, if true, renders the template
> into a String buffer, writing the result to the actual Writer only if it
> succeeded.
> Something like:
> // Process the template
> Writer writer = getWriter();
> if (getWriteCompleted()) {
> CharArrayWriter charArrayWriter = new CharArrayWriter();
> template.process(model, charArrayWriter);
> charArrayWriter.flush();
> charArrayWriter.writeTo(writer);
> } else {
> template.process(model, writer);
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.