Associate template with controller

View: New views
8 Messages — Rating Filter:   Alert me  

Associate template with controller

by Dean Del Ponte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it possible to associate a template with a controller so that the
controller is called before the template is rendered, or must a model
always be passed into a template from it's parent gsp?

Thanks,

Dean

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

    http://xircles.codehaus.org/manage_email



Re: Associate template with controller

by Jon Gunnip :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jul 1, 2008 at 8:09 PM, Dean Del Ponte <ddelponte@...> wrote:
> Is it possible to associate a template with a controller so that the
> controller is called before the template is rendered, or must a model
> always be passed into a template from it's parent gsp?

I'm not sure exactly what your use case is, but you also can call a
template directly from a controller or taglib using the tag as a
method call: g.render(template: "displaybook", model:
"['book':book,'author':author]").

See http://grails.org/doc/1.0.x/guide/6.%20The%20Web%20Layer.html#6.2.2.6%20Tags%20as%20Method%20Calls.

Jon

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

    http://xircles.codehaus.org/manage_email



Re: Associate template with controller

by Dean Del Ponte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a trackList page which lists all of the tracks from my cd  
collection.  I have a _playlistTemplate which I would also like to  
display on the before mentioned trackList page.  In order for the  
template to display properly, it needs access to a model, which would  
presumably contain a playlist object populated with tracks.

User's may add tracks to the playlist  from the trackList page by  
clicking the "add" button next to the desired track.

What is the recommended way of dealing with this scenario?  Should the  
trackList page also maintain a PlayList object which it passes into  
the playlistTemplate?

If I render the playlistTemplate from the trackList controller, won't  
that skip rendering of the trackList gsp?

I'm still new to the Grails thing.

Hope this didn't confuses the issue and thanks for your help.

- Dean

On Jul 1, 2008, at 9:53 PM, Jon Gunnip wrote:

> On Tue, Jul 1, 2008 at 8:09 PM, Dean Del Ponte <ddelponte@...>  
> wrote:
>> Is it possible to associate a template with a controller so that the
>> controller is called before the template is rendered, or must a model
>> always be passed into a template from it's parent gsp?
>
> I'm not sure exactly what your use case is, but you also can call a
> template directly from a controller or taglib using the tag as a
> method call: g.render(template: "displaybook", model:
> "['book':book,'author':author]").
>
> See http://grails.org/doc/1.0.x/guide/6.%20The%20Web%20Layer.html#6.2.2.6%20Tags%20as%20Method%20Calls 
> .
>
> Jon
>
> ---------------------------------------------------------------------
> 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



Re: Associate template with controller

by Jon Gunnip :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jul 1, 2008 at 9:03 PM, Dean Del Ponte <ddelponte@...> wrote:

> I have a trackList page which lists all of the tracks from my cd collection.
>  I have a _playlistTemplate which I would also like to display on the before
> mentioned trackList page.  In order for the template to display properly, it
> needs access to a model, which would presumably contain a playlist object
> populated with tracks.
>
> User's may add tracks to the playlist  from the trackList page by clicking
> the "add" button next to the desired track.
>
> What is the recommended way of dealing with this scenario?  Should the
> trackList page also maintain a PlayList object which it passes into the
> playlistTemplate?

If I understand you correctly, then the process I normally do for the
above scenario is pass all the data that trackList.gsp and
_playlistTemplate.gsp needs into the model when you render
trackList.gsp from the controller: render(view: "trackList",
model:[tracks: tracks, playlist: playlist]).  Then in trackList.gsp
you call <g:render template="playlistTemplate" model="[playlist:
playlist]" /> and pass the necessary data through to the template.

Jon

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

    http://xircles.codehaus.org/manage_email



Re: Associate template with controller

by Dean Del Ponte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Great!  I think that will work.

Thanks... I appreciate the help.

On Jul 1, 2008, at 10:31 PM, Jon Gunnip wrote:

> On Tue, Jul 1, 2008 at 9:03 PM, Dean Del Ponte <ddelponte@...>  
> wrote:
>> I have a trackList page which lists all of the tracks from my cd  
>> collection.
>> I have a _playlistTemplate which I would also like to display on  
>> the before
>> mentioned trackList page.  In order for the template to display  
>> properly, it
>> needs access to a model, which would presumably contain a playlist  
>> object
>> populated with tracks.
>>
>> User's may add tracks to the playlist  from the trackList page by  
>> clicking
>> the "add" button next to the desired track.
>>
>> What is the recommended way of dealing with this scenario?  Should  
>> the
>> trackList page also maintain a PlayList object which it passes into  
>> the
>> playlistTemplate?
>
> If I understand you correctly, then the process I normally do for the
> above scenario is pass all the data that trackList.gsp and
> _playlistTemplate.gsp needs into the model when you render
> trackList.gsp from the controller: render(view: "trackList",
> model:[tracks: tracks, playlist: playlist]).  Then in trackList.gsp
> you call <g:render template="playlistTemplate" model="[playlist:
> playlist]" /> and pass the necessary data through to the template.
>
> Jon
>
> ---------------------------------------------------------------------
> 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



Can't get text from RichUI text editor

by Patrick Haggood :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Using remoteform to insert simple two-param record into db; the 'title'
saves fine but I'm not getting the text from the richUI control.

This controller method displays my form:

    // swap out login menu with edit menu
    def editPlog = {
        def plog = new Plog()
        // for the list
        if(!params.max) params.max = 10
        [ plogList: Plog.list( params ).reverse() ]
        // the editor
        render(template:"editPlog", model:"[plog;plog]")
    }

The form:

<g:formRemote  name="addPlog"
url="[controller:'plog',action:'savePlog']" update="plogListBody" >
  <p><label for="title">title:</label>
  <g:textField name="title" value="${plog?.title}"/></p>
  <p><richui:richTextEditor name="entry" value="${plog?.entry}"
width="400" /></p>
  <p><g:submitButton name="submit" value="Submit" /></p>
  </g:formRemote>
  <g:remoteLink controller="plog"
      action="list">
    Cancel
  </g:remoteLink>

I hit 'save' and the richUI text is not saved.  

    // save plog inline; on !error swap privatelist into plogListBody,
else just update error msg
    def savePlog = {
        def plog = new Plog(params)
        println "saving " + plog.title + " " + plog.entry
        if(!plog.hasErrors() && plog.save()) {
                 def plogList = Plog.list().reverse()
                 render(template: "privateList", model:[plogList: plogList])
        }
        else {
            flash.message = "Plog not saved"
        }
    }

What am I doing wrong with this widget?


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

    http://xircles.codehaus.org/manage_email



Re: Can't get text from RichUI text editor

by Andreas Schmitt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Patrick,

adding before="tinyMCE.triggerSave()" to formRemote should solve it:

<g:formRemote  name="addPlog"
url="[controller:'plog',action
:'savePlog']" update="plogListBody" before="tinyMCE.triggerSave()">
 <p><label for="title">title:</label>
 <g:textField name="title" value="${plog?.title}"/></p>
 <p><richui:richTextEditor name="entry" value="${plog?.entry}"
width="400" /></p>
 <p><g:submitButton name="submit" value="Submit" /></p>
 </g:formRemote>
 <g:remoteLink controller="plog"
     action="list">
   Cancel
 </g:remoteLink>


Regards,
Andreas 

2008/7/8 Patrick Haggood <codezilla@...>:
Using remoteform to insert simple two-param record into db; the 'title'
saves fine but I'm not getting the text from the richUI control.

This controller method displays my form:

   // swap out login menu with edit menu
   def editPlog = {
       def plog = new Plog()
       // for the list
       if(!params.max) params.max = 10
       [ plogList: Plog.list( params ).reverse() ]
       // the editor
       render(template:"editPlog", model:"[plog;plog]")
   }

The form:

<g:formRemote  name="addPlog"
url="[controller:'plog',action:'savePlog']" update="plogListBody" >
 <p><label for="title">title:</label>
 <g:textField name="title" value="${plog?.title}"/></p>
 <p><richui:richTextEditor name="entry" value="${plog?.entry}"
width="400" /></p>
 <p><g:submitButton name="submit" value="Submit" /></p>
 </g:formRemote>
 <g:remoteLink controller="plog"
     action="list">
   Cancel
 </g:remoteLink>

I hit 'save' and the richUI text is not saved.

   // save plog inline; on !error swap privatelist into plogListBody,
else just update error msg
   def savePlog = {
       def plog = new Plog(params)
       println "saving " + plog.title + " " + plog.entry
       if(!plog.hasErrors() && plog.save()) {
                def plogList = Plog.list().reverse()
                render(template: "privateList", model:[plogList: plogList])
       }
       else {
           flash.message = "Plog not saved"
       }
   }

What am I doing wrong with this widget?


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

   http://xircles.codehaus.org/manage_email




Re: Can't get text from RichUI text editor

by Patrick Haggood :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That was the trick - thanks Andreas!



On Tue, 2008-07-08 at 14:38 +0200, Andreas Schmitt wrote:

>                              From:
> Andreas Schmitt
> <andreas.schmitt.mi@...>
>                          Reply-To:
> user@...
>                                To:
> user@...
>                           Subject:
> Re: [grails-user] Can't get text
> from RichUI text editor
>                              Date:
> Tue, 8 Jul 2008 14:38:19 +0200
> (08:38 EDT)
>
>
> Hi Patrick,
>
> adding before="tinyMCE.triggerSave()" to formRemote should solve it:


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

    http://xircles.codehaus.org/manage_email


LightInTheBox - Buy quality products at wholesale price