Is it possible to serve a GSP without controller intervention?

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

Is it possible to serve a GSP without controller intervention?

Matthias Bohlen-2
Hi,

I want to display a couple of help pages for my app, let's say help1.gsp
to help39.gsp. Do I need a controller for this or can I link to them
directly as I would do it with an ordinary website? How?

Cheers,
Matthias


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to serve a GSP without controller intervention?

rstudner
Look in your:

<app dir>/grails-app/config for a file called UrlMappings
You can define a static mapping, that directly renders a particular view.

Roger


On Fri, Jul 24, 2009 at 12:19 PM, Matthias Bohlen<[hidden email]> wrote:

> Hi,
>
> I want to display a couple of help pages for my app, let's say help1.gsp
> to help39.gsp. Do I need a controller for this or can I link to them
> directly as I would do it with an ordinary website? How?
>
> Cheers,
> Matthias
>
>
> ---------------------------------------------------------------------
> 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: Is it possible to serve a GSP without controller intervention?

Scott Burch
In reply to this post by Matthias Bohlen-2
I do this all the time.  These are off the top of my head so forgive any
typos, but they are close.

One way (and I think the best way) is to create a URL mapping like this

"/staticView/$view" {
        controller: 'staticView'
        action: 'view'
}

Create a StaticView controller

controller StaticView {
        view = {
                render(view:params.view)
        }
}

Or you can simply link to the GSP in your view

<g:link controller="viewDirectory" action="something.gsp">text</g:link>

or you can use a <a> tag the same way.

On Fri, 2009-07-24 at 18:19 +0200, Matthias Bohlen wrote:

> Hi,
>
> I want to display a couple of help pages for my app, let's say help1.gsp
> to help39.gsp. Do I need a controller for this or can I link to them
> directly as I would do it with an ordinary website? How?
>
> Cheers,
> Matthias
>
>
> ---------------------------------------------------------------------
> 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: Is it possible to serve a GSP without controller intervention?

tomas lin
In reply to this post by Matthias Bohlen-2
In grails-app/conf/UrlMappings.groovy

static mappings = {
      "/help1"(view:"/help1")
}

http://www.grails.org/doc/1.1/guide/single.html#6.4.3%20Mapping%20to%20Views

But you might want to do something like

static mappings = {
   "/helpPage?"(controller:"help")
}

and then use the controller to render the view to keep your
urlmappings file clean.

On Fri, Jul 24, 2009 at 5:19 PM, Matthias Bohlen<[hidden email]> wrote:

> Hi,
>
> I want to display a couple of help pages for my app, let's say help1.gsp
> to help39.gsp. Do I need a controller for this or can I link to them
> directly as I would do it with an ordinary website? How?
>
> Cheers,
> Matthias
>
>
> ---------------------------------------------------------------------
> 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: Is it possible to serve a GSP without controller intervention?

Mahboob
In reply to this post by Scott Burch
The solution given by Scott Burch is quite good. Only two things -

The typo in URL mapping needs to be corrected. It should be = and not :

"/staticView/$view" {
        controller = 'staticView'
        action = 'view'
}

Secondly, the keyword in StaticViewController is class, so the code is
class StaticViewController {
 
    def view = {
        println params.view
        render(view:params.view)
    }
}