You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Nathan Bubna (JIRA)" <ji...@apache.org> on 2005/09/15 19:21:54 UTC
[jira] Closed: (VELOCITY-212) Modify mergeTemplate() method in VelocityViewServlet to use response.getWriter()
[ http://issues.apache.org/jira/browse/VELOCITY-212?page=all ]
Nathan Bubna closed VELOCITY-212:
---------------------------------
Assign To: (was: Daniel Rall)
this was also resolved in the 1.1 release.
> Modify mergeTemplate() method in VelocityViewServlet to use response.getWriter()
> --------------------------------------------------------------------------------
>
> Key: VELOCITY-212
> URL: http://issues.apache.org/jira/browse/VELOCITY-212
> Project: Velocity
> Type: Bug
> Components: Tools
> Versions: 1.4
> Environment: Operating System: All
> Platform: All
> Reporter: Matthew Payne
>
> Modify the mergeTemplate() method of the VelocityViewServlet
> To use
> PrintWriter pw = response.getWriter();
> And use the PrintWriter instead of the ServletOutputStream.
> Refer to: http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg41885.html
> In short -----------------------------------------------------------
> you can't call response.getOutputStream() if something else called
> response.getWriter() in the same request.
> You will get an IllegalStateExeption.
> jsp calls response.getWriter(), lets be compatible with them
> ----------------------------------------------------------
> Why--->
> This appears to work very well. I tested this on tomcat and resin.
> By using response.getWriter(), this simple change would make the VelocityServlet
> "more" compatible with jsp(can be included in jsp's). This should enabled
> velocity to be have better interchangeability with tiles/jsp.
> Mixed tiles definitions like this will work fine.
> <definition name="jsplayout"
> path="/layout.jsp">
> >> <put name="header"
> >> value="/header.vm"/>
> >> <put name="footer"
> >> value="/footer.jsp"/>
> >> <put name="body"
> >> value="/center/listThemes.vm"/>
> >> <put name="rail"
> >> value="/rail.jsp"/>
> >> </definition>
> Here is the message from the user list.
> http://www.mail-archive.com/velocity-user@jakarta.apache.org/msg10683.html
> Note though, this change will not completely help the opposite, where a
> definition is based on a velocity layout.
> i.e.
> <definition name="vmlayout"
> path="/layout.vm">
> >> <put name="header"
> >> value="/header.vm"/>
> >> <put name="footer"
> >> value="/footer.jsp"/>
> >> <put name="body"
> >> value="/center/listThemes.vm"/>
> >> <put name="rail"
> >> value="/rail.jsp"/>
> >> </definition>
> In order for that to work, it would require an additional change to the tiles
> tool. I know what needs to be done, but holding that for another discussion.
> Here is what I have for my mergeTemplate()
> /**
> * merges the template with the context. Only override this if you really,
> really
> * really need to. (And don't call us with questions if it breaks :)
> *
> * @param template template object returned by the handleRequest() method
> * @param context context created by the createContext() method
> * @param response servlet reponse (use this to get the output stream or Writer
> */
> protected void mergeTemplate(Template template,
> Context context,
> HttpServletResponse response)
> throws ResourceNotFoundException, ParseErrorException,
> MethodInvocationException, IOException,
> UnsupportedEncodingException, Exception
> {
> PrintWriter vw = response.getWriter();
> try
> {
> template.merge(context, vw);
> }
> finally
> {
> try
> {
> if (vw != null)
> {
> // flush and put back into the pool
> // don't close to allow us to play
> // nicely with others.
> vw.flush();
> /* This hack sets the VelocityWriter's internal ref to the
> * OutputStreamWriter to null to keep memory free while
> * the writer is pooled. See bug report #18951 */
> }
> }
> catch (Exception e)
> {
> //Velocity.error("Error merging template \"" + template.getName()
> + "\": " + e);
>
> // if there is a problem with the writer, Velocity.error may not work
> either.
> e.printStackTrace(); //instead?
> // do nothing
> }
> }
> }
> Evaluate the last try/catch you may of may now want to use Velocity.error
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org