Bella
Bella

Reputation: 185

redirect from class to gsp page

I use grails and in service I have class in which before throw an exception it have to redirect to gsp page.

Is there anyone who know how to redirect from class to gsp?

Thanks in advance.

Upvotes: 0

Views: 452

Answers (2)

Bozho
Bozho

Reputation: 597224

Simply use redirect(uri:'foo'), which will redirect to foo.gsp.

Update: you should not redirect from service. Services must be completely unaware of the web nature of the application. So, at most, redirection can depend on some return value by a service.

Upvotes: 0

Hoàng Long
Hoàng Long

Reputation: 10848

Actually, redirect is designed to be used at the controllers, not services. Services should contain only the logic of your business, not the routing. Routing is the role of controllers. Moreover, if you throw an exception and then redirect, who will take the exception?

I think the better way is catching the exception thrown by the service at controller level, then do the redirecting.

You can view more abour redirect command here.

Upvotes: 3

Related Questions