Issue Details (XML | Word | Printable)

Key: WW-1808
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Jasper Rosenberg
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Struts 2

Support Freemarker template_exception_handler=rethrow

Created: 13/Mar/07 02:49 PM   Updated: 17/Jul/09 07:02 PM
Return to search
Component/s: Plugin - Tags
Affects Version/s: 2.0.6
Fix Version/s: 2.1.0

Issue Links:
Reference
 

Flags: Patch


 Description  « Hide
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);
}

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
Struts #551022 Wed Jun 27 03:29:53 UTC 2007 musachy WW-1808 Support Freemarker template_exception_handler=rethrow
* new attribute "writeIfCompleted" was added to FreeMarkerResult which if set
 to true will write to the stream only when there isn't any error processing
 the template (false by default)
Files Changed
MODIFY /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
MODIFY /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
ADD /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
ADD /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker
ADD /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/someFreeMarkerFile.ftl