mlathe
mlathe

Reputation: 2385

Grails: reusing an action

I'm building an application that among other things allows users to upload documents. I have the basic create/view actions working just fine, but i'd like to reuse this action in other places.

I want to know if anyone has a pointer for how to do this. There doesn't seem to be a very good way of doing this.

Here are a few ways i've considered:

  1. Try to do a chain(). This doesn't work since chaining does a GET, and to upload you need a POST.
  2. Break out the main business logic into the Grails "service", and make two actions that use the same code.
  3. Use a JS modal window. I've been thinking a modal that contains an iframe to an "unskinned" version of the document upload. The trick here is to get the window to close when the upload is done.

Thanks

--Matthias

Upvotes: 0

Views: 539

Answers (2)

Gregg
Gregg

Reputation: 35864

I don't care for the extending controller method. In fact, I avoid inheritance when possible. I'd rather put the common code in a service class and reuse it that way.

Upvotes: 5

Bozho
Bozho

Reputation: 597016

You can use a base controller class, and place the common functionality there. Then extend the base controller and call the method from other action methods.

Upvotes: 1

Related Questions