Grails1.2.1和Webflow插件(1.2.1)-未返回参数
我第一次使用Grails的webflow插件,遇到了一些困难。 总之,一旦进入Webflow,就不会有任何信息从表单返回到控制器。我看过的所有示例都表明,参数会正常返回到控制器操作,然后您可以根据需要将对象放入流范围。不幸的是,图示的println都输出null,params的任何编程输出都表明预期的“testField1”和“testField2”不在params对象中。请原谅那些不统一的文本框和提交方式——它们是实验的结果。 控制器操作流的简化版本:Grails1.2.1和Webflow插件(1.2.1)-未返回参数,grails,spring-webflow,grails-plugin,Grails,Spring Webflow,Grails Plugin,我第一次使用Grails的webflow插件,遇到了一些困难。 总之,一旦进入Webflow,就不会有任何信息从表单返回到控制器。我看过的所有示例都表明,参数会正常返回到控制器操作,然后您可以根据需要将对象放入流范围。不幸的是,图示的println都输出null,params的任何编程输出都表明预期的“testField1”和“testField2”不在params对象中。请原谅那些不统一的文本框和提交方式——它们是实验的结果。 控制器操作流的简化版本: def generateProductV
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")
}
}
<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>
GSP和司令部同样简单-
选择AttributeValue 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>
为什么要使用链接而不是提交按钮来触发下一个事件
<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>
单击该链接将执行GET请求,该请求不包括表单字段
<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>
您需要使用提交按钮来触发下一个事件
<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>
干杯
<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>
李是的,这肯定是个问题。这个链接是我在尝试让表单提交到流操作时使用的。不幸的是,我走这条路的根本原因是根本没有执行流操作(请求的资源不可用)。我仍然不知道为什么链接会点击操作,但是提交按钮没有。嗨,actionSubmit没有考虑WebFlow,你需要使用谢谢-正如你所说的,不理解grails g:actionSubmit和g:submitButton之间的区别是我的问题。
<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>