how can i render to the gsp view of other controller?

こ雲淡風輕ζ 提交于 2019-12-04 11:20:42

问题


I m new to grails,just started with a small application,

I'm searching a solution for below problem,

Can any one tell me how can i render to GSP view page of other controller from current controller view page.

With advance Thanks, Laxmi.P


回答1:


Lets suppose you want to render finalView.gsp of FirstController from normalView.gsp of SecondController having the following structure :

FirstController.groovy
   finalView.gsp
SecondController.groovy
   normalView.gsp

normalView.gsp will have :

<g:link controller="SecondController" action="redirectToFirstController">Redirect to finalView.gsp </g:link>

Then inside your SecondController, define one action called redirectToFirstController

def redirectToFirstController =  {
 redirect(controller:"FirstController",action:"renderFinalView")
}

And inside your FirstController:

def renderFinalView = {
render(view:"finalView");
}



回答2:


You can use either render(view: '/ctrlr/action', model: [fooInstance: foo]) or redirect(controller: 'ctrlr', action: 'action') controller dynamic methods in your action, depending on if you need to user a model you already have, or to completely redirect to that action's logic.

If you're asking about GSP code, there is a render tag.




回答3:


not quite sure but I think you have to use ModelAndView Class.

return new ModelAndView("/controller/view", [ model : youModel ])


来源:https://stackoverflow.com/questions/5896915/how-can-i-render-to-the-gsp-view-of-other-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!