Calling tag libs from controllers?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling tag libs from controllers?

Steven Devijver
Hey,

Is it possible to call tag libs from within the render() method in controllers?

Thanks

Steven

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

peter_m
I have issues doing this in 0.6 whenever I make the render() a JSON
builder. I have to prepare variables in advance and then refer to them
in the builder instead of calling the methods directly in the builder.

On 10/31/07, Steven Devijver <[hidden email]> wrote:

> Hey,
>
> Is it possible to call tag libs from within the render() method in controllers?
>
> Thanks
>
> Steven
>
> ---------------------------------------------------------------------
> 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: Calling tag libs from controllers?

Graeme-Rocher
In reply to this post by Steven Devijver
Since this functionality uses method missing you have to use as Peter suggested

Cheers

On 10/31/07, Steven Devijver <[hidden email]> wrote:

> Hey,
>
> Is it possible to call tag libs from within the render() method in controllers?
>
> Thanks
>
> Steven
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.com

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Steven Devijver
In reply to this post by peter_m
How to you prepare these variables then?

Thanks

Steven

On 10/31/07, Peter Mondlock <[hidden email]> wrote:

> I have issues doing this in 0.6 whenever I make the render() a JSON
> builder. I have to prepare variables in advance and then refer to them
> in the builder instead of calling the methods directly in the builder.
>
> On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > Hey,
> >
> > Is it possible to call tag libs from within the render() method in controllers?
> >
> > Thanks
> >
> > Steven
> >
> > ---------------------------------------------------------------------
> > 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
>
>

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

peter_m
In my case, I'm using the message() tag, so what I do is simply this
(pseudocode-ish):

def msgs = domain.errors.allErrors.collect { e-> message(code:e) }
render(builder:'json') {
   messages(msgs)
}

I just slapped this together, so you might have to mess around with it
to get it to work.

On 10/31/07, Steven Devijver <[hidden email]> wrote:

> How to you prepare these variables then?
>
> Thanks
>
> Steven
>
> On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > I have issues doing this in 0.6 whenever I make the render() a JSON
> > builder. I have to prepare variables in advance and then refer to them
> > in the builder instead of calling the methods directly in the builder.
> >
> > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > Hey,
> > >
> > > Is it possible to call tag libs from within the render() method in controllers?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> ---------------------------------------------------------------------
> 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: Calling tag libs from controllers?

Graeme-Rocher
On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> In my case, I'm using the message() tag, so what I do is simply this
> (pseudocode-ish):
>
> def msgs = domain.errors.allErrors.collect { e-> message(code:e) }
> render(builder:'json') {
>    messages(msgs)
> }

Nice little bit of code that ;-)

Cheers

>
> I just slapped this together, so you might have to mess around with it
> to get it to work.
>
> On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > How to you prepare these variables then?
> >
> > Thanks
> >
> > Steven
> >
> > On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > > I have issues doing this in 0.6 whenever I make the render() a JSON
> > > builder. I have to prepare variables in advance and then refer to them
> > > in the builder instead of calling the methods directly in the builder.
> > >
> > > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > > Hey,
> > > >
> > > > Is it possible to call tag libs from within the render() method in controllers?
> > > >
> > > > Thanks
> > > >
> > > > Steven
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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
>
>


--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.com

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Steven Devijver
In reply to this post by peter_m
I'm trying this but it doesn't seem to call the taglibs:

                def x = {
                        form(controller:'report', action:'findNewReportDetails') {
                                table {
                                        tbody {
                                                tr {
                                                        td(class:'name', 'test')
                                                        td(class:'value') {
                                                                textField(name:'testSelector')
                                                        }
                                                }
                                        }
                                }
                        }
                }
               
                render(contentType:"text/html") {
                        h1("Create new report from '${report.reportName}' (${report.environment})")
                        div(class:"dialog", x)
                }


Steven

On 10/31/07, Peter Mondlock <[hidden email]> wrote:

> In my case, I'm using the message() tag, so what I do is simply this
> (pseudocode-ish):
>
> def msgs = domain.errors.allErrors.collect { e-> message(code:e) }
> render(builder:'json') {
>    messages(msgs)
> }
>
> I just slapped this together, so you might have to mess around with it
> to get it to work.
>
> On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > How to you prepare these variables then?
> >
> > Thanks
> >
> > Steven
> >
> > On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > > I have issues doing this in 0.6 whenever I make the render() a JSON
> > > builder. I have to prepare variables in advance and then refer to them
> > > in the builder instead of calling the methods directly in the builder.
> > >
> > > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > > Hey,
> > > >
> > > > Is it possible to call tag libs from within the render() method in controllers?
> > > >
> > > > Thanks
> > > >
> > > > Steven
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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
>
>

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Steven Devijver
Guys,

I can't seem to get the taglibs working in controllers, as shown
below. Am I doing something wrong, or should it work?

Thanks

Steven

On 10/31/07, Steven Devijver <[hidden email]> wrote:

> I'm trying this but it doesn't seem to call the taglibs:
>
>                 def x = {
>                         form(controller:'report', action:'findNewReportDetails') {
>                                 table {
>                                         tbody {
>                                                 tr {
>                                                         td(class:'name', 'test')
>                                                         td(class:'value') {
>                                                                 textField(name:'testSelector')
>                                                         }
>                                                 }
>                                         }
>                                 }
>                         }
>                 }
>
>                 render(contentType:"text/html") {
>                         h1("Create new report from '${report.reportName}' (${report.environment})")
>                         div(class:"dialog", x)
>                 }
>
>
> Steven
>
> On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > In my case, I'm using the message() tag, so what I do is simply this
> > (pseudocode-ish):
> >
> > def msgs = domain.errors.allErrors.collect { e-> message(code:e) }
> > render(builder:'json') {
> >    messages(msgs)
> > }
> >
> > I just slapped this together, so you might have to mess around with it
> > to get it to work.
> >
> > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > How to you prepare these variables then?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > > On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > > > I have issues doing this in 0.6 whenever I make the render() a JSON
> > > > builder. I have to prepare variables in advance and then refer to them
> > > > in the builder instead of calling the methods directly in the builder.
> > > >
> > > > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > > > Hey,
> > > > >
> > > > > Is it possible to call tag libs from within the render() method in controllers?
> > > > >
> > > > > Thanks
> > > > >
> > > > > Steven
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > 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
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Marc Palmer Local

On 2 Nov 2007, at 10:19, Steven Devijver wrote:

> Guys,
>
> I can't seem to get the taglibs working in controllers, as shown
> below. Am I doing something wrong, or should it work?
>
I doubt it will work in that case as it is implemented using  
missingMethod in the controller I believe. Therefore this hinges on  
whether the closure you have has the correct delegate set.

It might work if you do x.delegate = this before calling render?

>
Marc


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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Graeme-Rocher
In reply to this post by Steven Devijver
That is not a supported syntax.

Your closure has to return a string for the body, and the tag itself
will return a string:

def result = form(controller:'report', action:'findNewReportDetails') {
     "<table>remaining html</table"
}

Also you should use namespacing:

def result = g.form(controller:'report', action:'findNewReportDetails') {
     "<table>remaining html</table"
}

Which is also the way you render GSPs to a strings:

def result = g.render(template:"foo")


Cheers

On 11/2/07, Steven Devijver <[hidden email]> wrote:

> Guys,
>
> I can't seem to get the taglibs working in controllers, as shown
> below. Am I doing something wrong, or should it work?
>
> Thanks
>
> Steven
>
> On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > I'm trying this but it doesn't seem to call the taglibs:
> >
> >                 def x = {
> >                         form(controller:'report', action:'findNewReportDetails') {
> >                                 table {
> >                                         tbody {
> >                                                 tr {
> >                                                         td(class:'name', 'test')
> >                                                         td(class:'value') {
> >                                                                 textField(name:'testSelector')
> >                                                         }
> >                                                 }
> >                                         }
> >                                 }
> >                         }
> >                 }
> >
> >                 render(contentType:"text/html") {
> >                         h1("Create new report from '${report.reportName}' (${report.environment})")
> >                         div(class:"dialog", x)
> >                 }
> >
> >
> > Steven
> >
> > On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > > In my case, I'm using the message() tag, so what I do is simply this
> > > (pseudocode-ish):
> > >
> > > def msgs = domain.errors.allErrors.collect { e-> message(code:e) }
> > > render(builder:'json') {
> > >    messages(msgs)
> > > }
> > >
> > > I just slapped this together, so you might have to mess around with it
> > > to get it to work.
> > >
> > > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > > How to you prepare these variables then?
> > > >
> > > > Thanks
> > > >
> > > > Steven
> > > >
> > > > On 10/31/07, Peter Mondlock <[hidden email]> wrote:
> > > > > I have issues doing this in 0.6 whenever I make the render() a JSON
> > > > > builder. I have to prepare variables in advance and then refer to them
> > > > > in the builder instead of calling the methods directly in the builder.
> > > > >
> > > > > On 10/31/07, Steven Devijver <[hidden email]> wrote:
> > > > > > Hey,
> > > > > >
> > > > > > Is it possible to call tag libs from within the render() method in controllers?
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > > Steven
> > > > > >
> > > > > > ---------------------------------------------------------------------
> > > > > > 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
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.com

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Calling tag libs from controllers?

Steven Devijver
In reply to this post by Marc Palmer Local
Hey Marc,

I doubt that will work since the render method has to set a delegate
on the closure before calling it. I haven't tried though, I'm using
template now :-)

Thanks

Steven

On 11/2/07, Marc Palmer <[hidden email]> wrote:

>
> On 2 Nov 2007, at 10:19, Steven Devijver wrote:
>
> > Guys,
> >
> > I can't seem to get the taglibs working in controllers, as shown
> > below. Am I doing something wrong, or should it work?
> >
> I doubt it will work in that case as it is implemented using
> missingMethod in the controller I believe. Therefore this hinges on
> whether the closure you have has the correct delegate set.
>
> It might work if you do x.delegate = this before calling render?
>
> >
> Marc
>
>
> ---------------------------------------------------------------------
> 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