问题出在这里:我有一个remoteForm,它本身可以正常工作。我调试了 Controller ,并通过了所有命令。但是,如果发生异常,并且我设置了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>
......
Controller :
......
} catch (Exception e){
log.error(e)
flash.error = e.getMessage()
flash.message="HINTTEST"
render (template:'searchNoResult')
return
}
.....
(_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>
文档说:Flash作用域贯穿于当前请求和之后的调用。如果我使用普通形式并提交所有正常工作的文件,但是我想使用ajax和渲染模板,那么我不必如此频繁地重复代码。
编辑1
首先显示index.gsp。 remoteForm使用包含flash.messages的模板更改seachBlock div。他们没有被填补。
Grails版本1.3.7目前无法升级。
编辑2
异常(exception)e不是我最初抛出的异常(exception)。消息为空,导致消息为空。...
最佳答案
从您显示的代码来看,ajax请求返回响应时,没有任何消息更新info_message div。 formRemote仅更新searchBlock元素。 如果页面不刷新flash.message将无法呈现。