Ah, even better.  So using this approach I now have Panels rendering fine
with jsp templates, by way of a custom JspTemplateService.

I'll look into contributing a patch for this in JIRA... do you suppose this
belongs in framework next to VelocityTemplateService, or in extras next to
the FreemarkerTemplateService?



On Fri, Mar 4, 2011 at 2:31 AM, Bob Schellink <[email protected]> wrote:

> Context is bound to a ThreadLocal so you can just look it up. No need to
> change method signatures.
>
> Bob
>
> On 2011/03/03 20:28 PM, Ari wrote:
> > Hi,
> >
> > In that case, what do you think about changing the
> TemplateService.renderTemplate() signature to
> > allow the Context to be passed in?
> >
> > Velocity and Freemarker TemplateServices would just ignore it and
> function exactly as before (they
> > could trivially implement the new signature by just calling the old one
> with a null), but a new
> > JspTemplateService could now use this Context to get the
> HttpServletRequest and Response, which
> > would allow it to render the Jsp normally via RequestDispatcher.include()
> >
> > If writing to an intermediate String is preferred instead of writing
> directly to output stream then
> > a mock HttpServletResponse can be passed in.  This mock instance would
> implement the
> > HttpServletResponse methods but would internally write to a StringWriter
> instead of the
> > OutputStream.  HttpServletResponseWrapper would make a handy starting
> point for writing such a class.
> >
> > Thoughts?  Should I repost in the dev forum?
> >
> > Thanks
> > Ari
> >
> >
> > On Thu, Mar 3, 2011 at 2:07 AM, Bob Schellink <[email protected] <mailto:
> [email protected]>> wrote:
> >
> >     Hi,
> >
> >     I'm not sure if that is possible actually. The question is how would
> you render the JSP template to
> >     a String which the Panel can return. If you know of a way you can
> create a custom Panel to achieve
> >     that. One route might be to create a custom HttpServletResponse using
> a ByteArray which you then
> >     forward to the container's JSP engine. Once it returns the byteArray
> should contain the content.
> >
> >     Bob
> >
> >
> >     On 2011/03/03 04:14 AM, Ari wrote:
> >     > Minor corrections to my own question...
> >     >
> >     > 1) userLinks is a List<PageLink>, not an array.
> >     >
> >     > 2) I've overridden the Panel's getTemplate(), not the Page's.  The
> page merely includes the Panel
> >     > like any other component.
> >     >
> >     > Thanks again for any suggestions as to what might be wrong.
> >     >
> >     > Ari
> >     >
> >     > On Wed, Mar 2, 2011 at 4:40 PM, Ari <[email protected]
> >     <mailto:[email protected]> <mailto:[email protected]
> >     <mailto:[email protected]>>>
> >     > wrote:
> >     >
> >     >     Hi,
> >     >
> >     >     I wondered if someone might have a working example of a Panel
> being used with a JSP as its
> >     view
> >     >     template.  JSPs work ok for me with regular Click Pages, but
> when I try to use a Panel, I get
> >     >     errors of this nature:
> >     >
> >     >     [Click] [error] Velocity: Parser Exception:
> >     >
> /mypath/mypanel-template.jsporg.apache.velocity.runtime.parser.ParseException:
> Encountered
> >     >     ":length(userLinks)}\n<div>
> >     >
> >     >     userLinks is an Array<PageLink> which I've defined in my
> Panel.java subclass, and am
> >     referencing
> >     >     in the JSP as shown in the error, so it is reaching the JSP.
>  But it seems like Click is
> >     trying
> >     >     to interpret the template as Velocity instead of JSP, even
> though I've overridden the Page's
> >     >     getTemplate() method to return a jsp file name (as demonstrated
> by the fact that it
> >     reaches the
> >     >     jsp!).
> >     >
> >     >     Any advice or examples would be much appreciated.
> >     >
> >     >     Thanks,
> >     >     Ari
> >     >
> >     >
> >
> >
>
>

Reply via email to