How to invoke an action without creating a view in grails

How can I call a method in one of my controller classes without grails trying to generate a view?

+5
source share
3 answers

You can redirect to do another controller action.

class PuppyController {

   def woof() {
     redirect(action:'bark')
   }

   def bark(){
     response.write "Moo"
   }

}

At some point, you should either write an answer or redirect the method / closure corresponding to the view so that the user can get the result.

If the method that you are trying to call is on another controller, most likely, it CANNOT BE WRONG.

, , , , , , (, timestamp + "pretty file for" + username) , Service .

+4
class FooController {

  def fooAction() {
    render("Successful call to fooAction")
  }

}
+2

Essentially, you can create an instance of the controller (via the keyword "new"), and then invoke the action of interest. Please provide more details on what you want to do so that I can give a better answer ...

0
source

All Articles