Using SiteMesh within g.render?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Using SiteMesh within g.render?

John Moore
I'm trying to do something which I thought would be simple but is turning out not to be. I need to render a reasonably complex page as PDF, using iText, using a view which is also used elsewhere to render the page as straight HTML. As long as I can get the HTML as an intermediate stage, I think I should be OK to generate the PDF (that's what I'm doing elsewhere).

What I am trying to do is to use g.render in my controller to capture the HTML which would otherwise be rendered to the response output stream. The problem is that I can't use a view as such in g.render, it has to be a template. So, I thought, I could just rename my "quote" view as "_quote", with the leading underscore, so it's recognizable as a template, and use that. When I do, though, it does not apply the 'main' layout named in the head ('<meta name="layout" content="main"/>') and just renders the bald undecorated HTML.

I took a look at using the PageRenderer which came along in Grails 2.0, but that has the same problem plus others as well (no knowledge of the request object, for example).

I presume that this is because SiteMesh works by means of a filter, which only kicks in once the Grails rendering engine has done its stuff.

At the moment I'm looking at using HTTPBuilder to fire off a request from my Grails application to itself, in order to be able to get hold of the complete HTML, but that seems a rather bizarre workaround to me. I'm hoping I've missed something simple which will allow me to somehow grab the complete, decorated output and render it as PDF. Maybe a filter which is called after SiteMesh?

Reply | Threaded
Open this post in threaded view
|

Re: Using SiteMesh within g.render?

lmivan

Hi,

You can use the rendering plugin: http://grails.org/plugin/rendering

Regards, Iván.

--
Sent from my Nexus 10

El 24/08/2013 13:49, "John Moore" <[hidden email]> escribió:
I'm trying to do something which I thought would be simple but is turning out
not to be. I need to render a reasonably complex page as PDF, using iText,
using a view which is also used elsewhere to render the page as straight
HTML. As long as I can get the HTML as an intermediate stage, I think I
should be OK to generate the PDF (that's what I'm doing elsewhere).

What I am trying to do is to use g.render in my controller to capture the
HTML which would otherwise be rendered to the response output stream. The
problem is that I can't use a view as such in g.render, it has to be a
template. So, I thought, I could just rename my "quote" view as "_quote",
with the leading underscore, so it's recognizable as a template, and use
that. When I do, though, it does not apply the 'main' layout named in the
head ('<meta name="layout" content="main"/>') and just renders the bald
undecorated HTML.

I took a look at using the PageRenderer which came along in Grails 2.0, but
that has the same problem plus others as well (no knowledge of the request
object, for example).

I presume that this is because SiteMesh works by means of a filter, which
only kicks in once the Grails rendering engine has done its stuff.

At the moment I'm looking at using HTTPBuilder to fire off a request from my
Grails application to itself, in order to be able to get hold of the
complete HTML, but that seems a rather bizarre workaround to me. I'm hoping
I've missed something simple which will allow me to somehow grab the
complete, decorated output and render it as PDF. Maybe a filter which is
called after SiteMesh?





--
View this message in context: http://grails.1312388.n4.nabble.com/Using-SiteMesh-within-g-render-tp4648343.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Using SiteMesh within g.render?

John Moore
lmivan wrote
Hi,

You can use the rendering plugin: http://grails.org/plugin/rendering
I thought about that (I've used it in the past), but I don't believe it will work for me, as it has the same issues as the g.render method, namely that it uses a template, not a full-blown view, and thus the SiteMesh issue would still apply. Please correct me if I'm wrong, though.
Reply | Threaded
Open this post in threaded view
|

Re: Using SiteMesh within g.render?

Rafael Vargas Rosas
In reply to this post by John Moore
Why do you not put your layout code in that template?

--

El 24/08/2013, a las 06:48, John Moore <[hidden email]> escribió:

> I'm trying to do something which I thought would be simple but is turning out
> not to be. I need to render a reasonably complex page as PDF, using iText,
> using a view which is also used elsewhere to render the page as straight
> HTML. As long as I can get the HTML as an intermediate stage, I think I
> should be OK to generate the PDF (that's what I'm doing elsewhere).
>
> What I am trying to do is to use g.render in my controller to capture the
> HTML which would otherwise be rendered to the response output stream. The
> problem is that I can't use a view as such in g.render, it has to be a
> template. So, I thought, I could just rename my "quote" view as "_quote",
> with the leading underscore, so it's recognizable as a template, and use
> that. When I do, though, it does not apply the 'main' layout named in the
> head ('<meta name="layout" content="main"/>') and just renders the bald
> undecorated HTML.
>
> I took a look at using the PageRenderer which came along in Grails 2.0, but
> that has the same problem plus others as well (no knowledge of the request
> object, for example).
>
> I presume that this is because SiteMesh works by means of a filter, which
> only kicks in once the Grails rendering engine has done its stuff.
>
> At the moment I'm looking at using HTTPBuilder to fire off a request from my
> Grails application to itself, in order to be able to get hold of the
> complete HTML, but that seems a rather bizarre workaround to me. I'm hoping
> I've missed something simple which will allow me to somehow grab the
> complete, decorated output and render it as PDF. Maybe a filter which is
> called after SiteMesh?
>
>
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Using-SiteMesh-within-g-render-tp4648343.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Using SiteMesh within g.render?

John Moore
Rafael Vargas Rosas wrote
Why do you not put your layout code in that template?
That's the direction I'm currently heading in. The problem is that it's messy to do that, as the view is quite complex, and I have been reluctant to in effect reverse the refactoring I did, moving the common HTML etc to the 'main' layout.

Or am I misunderstanding what you mean here?