M.R*_*.R. 1 grails groovy controller gsp
这是问题:我有一个remoteForm,它本身工作正常.我调试了控制器,每个命令都会运行.但是,如果发生异常并且我设置了flash.error消息.仅在我手动按F5(刷新)后才会显示该消息.我不明白为什么AJAX调用有效,但flash消息是空的.
我有一个远程表单(在index.gsp中):
...
<g:formRemote name="remoteForm"
url="[ controller: 'document',
action: 'search']"
onLoading="showSpinner();"
update="searchBlock"
action="${createLink(controller: 'document', action:'search')}"
>
<div class='info_message'>
${flash.message}
</div>
<div id="searchBlock">will be exchanged</div>
......
Run Code Online (Sandbox Code Playgroud)
控制器:
......
} catch (Exception e){
log.error(e)
flash.error = e.getMessage()
flash.message="HINTTEST"
render (template:'searchNoResult')
return
}
.....
Run Code Online (Sandbox Code Playgroud)
模板(_searchNoResult)具有以下内容:
<span>Sorry, your search yielded no result.</span>
<g:if test='${flash.error}'>
<div class='error_message'>
Error: ${flash.error}
</div>
</g:if>
<g:if test='${flash.messages}'>
<div class='info_message'>
Hint: ${flash.message}
</div>
</g:if>
Run Code Online (Sandbox Code Playgroud)
文档说明:闪存范围通过当前请求和之后的调用.如果我使用普通表单并提交一切正常,但我想使用ajax和渲染模板,所以我不必经常重复代码.
编辑1 首先渲染index.gsp.remoteForm使用包含flash.messages的模板更改seachBlock div.他们没有被填补.
Grails版本1.3.7目前无法升级.
编辑2 异常e,不是Exception,它是我原创的.消息为null,导致消息为null ....
从您已经显示的代码中,当ajax请求返回响应时,没有任何内容正在使用消息更新info_message div.formRemote仅更新searchBlock元素. 如果页面没有刷新flash.message无法呈现.
| 归档时间: |
|
| 查看次数: |
3486 次 |
| 最近记录: |