Grails 3.1.8 controller

自作多情 提交于 2019-12-13 06:28:38

问题


I'm converting a grails 2.4.4 app to 3.1.8. In some of my controller methods sometimes (based on what happened in the service call) I'll just set a message in the flash and nothing else, this was fine in 2.4.4, the screen would be re-rendered with the flash message but in 3.1.8 nothing is rendered at all, the screen in totally blank. Seemingly if I add a statement after setting the message in the flash the screen is rendered, the statement can be anything e.g. println 'hello' or return or new ModelAndView(). Example below:

def index() { 
def res = myService.whatever() 
if (res) { 
    [res: res] 
} 
else { 
    flash.message = message( code: 'no.res' )  // if we get here nothing is rendered
}
} 

Is this a change to grails 3 or am I missing something somewhere?

Thanks


回答1:


Try doing this

def index() { 
    def res = myService.whatever() 

    [res: res]
}

Then in the index.gsp view

<g:if test="${res}">
    <!-- cool thing goes here -->
</g:if>
<g:else>
    <g:message code="no.res"/>
</g:else>


来源:https://stackoverflow.com/questions/38170916/grails-3-1-8-controller

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