1
我第一次使用Grails的webflow插件,並且遇到一些困難。總之,一旦在Webflow中,沒有任何信息似乎從窗體返回到控制器。我所看到的所有示例都表明,params通常返回到控制器操作,然後可以根據需要將對象放入流作用域。不幸的是,所示的printlns都輸出null,並且任何params的輸出都顯示期望的'testField1'和'testField2'不在params對象中。請原諒不一致的文本框和提交方式 - 它們是實驗的結果。 控制器動作流程的簡化版本:帶Webflow插件的Grails 1.2.1(1.2.1) - params沒有被返回
def generateProductVariantsFlow = {
start() {
action {
[productInstance:Product.get(params.id)] //the entry params contains the expected id
}
on ("success").to("selectAttributeValues")
}
selectAttributeValues() {
on("next"){TestCommand tc -> //params does not have testField1 or testField2
println "TEST COMMAND"
println "${tc.testField1}"
println "${tc.testField2}"
}.to("selectProductVariants")
on("cancel").to("finishBeforeStart")
}
selectProductVariants {
on("cancel").to("finish")
on("previous").to("selectAttributeValues")
on("next").to("confirmNewVariants")
}
//other states here
finish {
redirect(action:"list")
}
finishBeforeStart { //somewhat misleading state name, but shouldn't be relevant
redirect(controller:"product",action:"show")
}
}
的GSP和命令也同樣簡單 - selectAttributeValues GSP:
<%@ page import="com.castaway.rigging.Product" %>
<g:form action="generateProductVariants">
<input type="integer" id="testField1" name="testField1" value="test1" />
<g:textField name="testField2" value="test2"/>
<div class="buttons">
<span class="button"><g:actionSubmit class="cancel" name="cancel" value="Cancel"/></span>
<g:link action="generateProductVariants" event="next" >Next</g:link>
</div>
</g:form>
</div>
</body>
命令:
class TestCommand implements Serializable {
def testField1
def testField2
}
是的,那肯定是有問題。這個鏈接是我在試圖讓表單提交到流動操作時玩過的。 不幸的是,我走下這條路的根本原因在於 根本沒有觸及流動作(請求資源不可用)。 我仍然不確定他們爲什麼鏈接命中動作,但提交按鈕沒有。 –
Aaron
2010-03-04 23:33:56
嗨, actionSubmit沒有考慮到WebFlow,你需要使用 –
leebutts
2010-03-05 01:26:15
謝謝 - 正如你所說的,不理解grails的區別g:actionSubmit和g:submitButton是我的問題。 – Aaron 2010-03-05 01:38:12