Exposing Controllers to the View

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

Exposing Controllers to the View

graemer
Now that we have new instances of controllers being created for each
request I think it would be a great idea to expose the controller to
the view as the model if no explicity model is returned.

This will allow you to have properties on your controllers like this:

class BookController {
     @Property books

     @Property list = {  this.books = Book.findAll()  }

}

This is similar to the way WebWork and RoR work.

We could then in the code wrap the controller in an Apache bean map to
expose its properties as the model:

new BeanMap(controller)

And this way the user has the choice whether to return an explicity
defined model (as a map) or the controller as a bean instance.

What do you think?

Graeme
Reply | Threaded
Open this post in threaded view
|

Re: Exposing Controllers to the View

Guillaume Laforge-2
On 19/12/05, Graeme Rocher <[hidden email]> wrote:

> Now that we have new instances of controllers being created for each
> request I think it would be a great idea to expose the controller to
> the view as the model if no explicity model is returned.
>
> This will allow you to have properties on your controllers like this:
>
> class BookController {
>      @Property books
>
>      @Property list = {  this.books = Book.findAll()  }
>
> }
>
> This is similar to the way WebWork and RoR work.
>
> We could then in the code wrap the controller in an Apache bean map to
> expose its properties as the model:
>
> new BeanMap(controller)
>
> And this way the user has the choice whether to return an explicity
> defined model (as a map) or the controller as a bean instance.
>
> What do you think?

This sounds interesting.
I think I'd tend to prefer returning maps for the model, but that's
certainly a handy addition to return the controller itself.

--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: Exposing Controllers to the View

graemer
On 20/12/05, Guillaume Laforge <[hidden email]> wrote:

> On 19/12/05, Graeme Rocher <[hidden email]> wrote:
> > Now that we have new instances of controllers being created for each
> > request I think it would be a great idea to expose the controller to
> > the view as the model if no explicity model is returned.
> >
> > This will allow you to have properties on your controllers like this:
> >
> > class BookController {
> >      @Property books
> >
> >      @Property list = {  this.books = Book.findAll()  }
> >
> > }
> >
> > This is similar to the way WebWork and RoR work.
> >
> > We could then in the code wrap the controller in an Apache bean map to
> > expose its properties as the model:
> >
> > new BeanMap(controller)
> >
> > And this way the user has the choice whether to return an explicity
> > defined model (as a map) or the controller as a bean instance.
> >
> > What do you think?
>
> This sounds interesting.
> I think I'd tend to prefer returning maps for the model, but that's
> certainly a handy addition to return the controller itself.

My concern is at the moment if you return null its fine, if you return
a map no problem.. but if you return anything else it throws an
exception which is not very user friendly. I think it should return
the controller as the model as the fallback rather than an exception

Graeme

>
> --
> Guillaume Laforge
> Groovy Project Manager
> http://glaforge.free.fr/blog/groovy
>
Reply | Threaded
Open this post in threaded view
|

Re: Exposing Controllers to the View

Guillaume Laforge-2
> My concern is at the moment if you return null its fine, if you return
> a map no problem.. but if you return anything else it throws an
> exception which is not very user friendly. I think it should return
> the controller as the model as the fallback rather than an exception

Sounds like a reasonable fallback tactic.

--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy