Grails的Webflow的使用Ajax
-
20-09-2019 - |
题
我想过渡到使用Ajax请求的Webflow的下一个状态。但它停留在相同的状态,并返回GSP作为响应的同时,我期待普惠制下一个状态的状态。
以下是Webflow的代码:
def gettingStartedAjaxFlow = {
flow1 {
on("next") {
println "flow1"
}.to("flow2")
on("skip").to("flow2")
}
flow2 {
on("next") {
println "flow2"
}.to("flow3")
on("skip").to("flow3")
}
flow3 {
on("next"){
println "flow3"
}.to("finish")
on("skip").to("finish")
finish {
redirect(action:"index")
}
}
}
以下是AJAX调用我正在为国家过渡:
$.ajax({
type: "POST",
url: "/UN/user/gettingStartedAjax",
success: function(data) {
$("#wizardDiv").html(data);
}
});
对于每个状态(流1,流2,FLOW3)的GSP的含有具有remoteForm&下一个所需要的代码段,并跳过提交按钮转换到下一个状态,并且作为一个结果来更新“wizardDiv”分区。以下是流1状态下的GSP片段:
<g:formRemote name="flow1Form" url="[controller:'user', action:'gettingStartedAjax']" update="wizardDiv">
<p>You are in flow 1</p>
<g:submitButton name="next" value="Next Flow" />
<g:submitButton name="skip" value="Skip Flow" />
</g:formRemote>
解决方案
以及保持执行的曲目(如达信发布的),你需要确保你的按钮命名为_eventId_next和_eventId_skip。 G:提交按钮通常是足够聪明的为你做这一点,但它可能不是一个remoteForm内
另外,我的网站流量的代码使用的参数执行,不flowExecutionKey - ?您使用它的Grails的版本
其他提示
我卡在同样的问题,近计算出来,
您需要做的,是发回的Webflow“_flowExecutionKey”,保持Grails的 轨道的当前状态,
我相信你已经看到的此时,作为其唯一的像样结果发现谷歌
我发送AJAX请求到一个动作,其中填充的模板,并将其发送回 与输入标签
<input id="flowExecutionKey" name="_flowExecutionKey" value="${request.flowExecutionKey}" size="100"/>
但你可以尝试发回标记像JSON寺庙与“_flowExecutionKey”随着数据要发送回来,
这是我的两分钱
下面,在Grails的2.5.3工作的解决方案至少为一个单一动作。按钮的标识和名称会自动修改为包括“ EVENTID 的”前缀,但是这仍然除非我手动添加_event_id作为输入参数,并没有为我工作。但是,我不知道如何可以为多个可能的事件工作。
<g:formRemote name="flow1Form" url="[controller:'user', action:'gettingStartedAjax']" update="wizardDiv">
<input type="hidden" id="execution" name="execution" value="${request.flowExecutionKey}"/>
<input type="hidden" id="_eventId" name="_eventId" value="next"/>
<fieldset class="form">
</fieldset>
<fieldset class="buttons">
<g:submitButton name="next" value="Next flow"/>
</fieldset>
</g:formRemote>
不隶属于 StackOverflow