我遇到了Spring Web Flow的问题。如果用户点击表单提交按钮,我的bean中将包含 RIGHT 值。
性别领域的例子是男性或女性。但是我添加了一个 AjaxEventDecoration 来改变性别下拉框提交,这实际上是一个形式:选择并且在bean中我将得到值“sex”,这是elementId。以下是我的代码,请您查看它并告诉我您的想法...我需要尽快修复此值......
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<style type="text/css" media="screen">
@import url("<c:url value="/resources/dojo/resources/dojo.css"/>");
@import url("<c:url value="/resources/dijit/themes/claro/claro.css"/>");
</style>
<script djconfig="parseOnLoad: true"
src="<c:url value="/resources/dojo/dojo.js"/>" type="text/javascript"></script>
<script type="text/javascript"
src="<c:url value="/resources/spring/Spring.js" />"> </script>
<script type="text/javascript"
src="<c:url value="/resources/spring/Spring-Dojo.js" />"></script>
<script type="text/javascript">dojo.require("dojo.parser");</script>
<html>
<head>
<title>Spring 3.0 MVC - Web Flow Example</title>
</head>
<body class="claro">
<h2>Dropdown Test</h2>
<form:form commandName="customer" id="customer">
<input type="hidden" name="_flowExecutionKey"
value="${flowExecutionKey}" />
<div id="container">
<table>
<tr>
<td><font color=red><form:errors path="sex" /></font><b>Sex:</b></td>
<td><form:select path="sex" id="sex">
<form:option value="MALE" label="MALE" />
<form:option value="FEMALE" label="FEMALE" />
</form:select>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "sex",
widgetType : "dijit.form.Select",
widgetAttrs : {
promptMessage : "Enter Sex",
required : true }}));
</script></td></tr>
</table>
</div>
<input type="submit" name="_eventId_submit" id="submit" value="Submit" />
<input type="submit" name="_eventId_cancel" value="Cancel" />
<p>
<script type="text/javascript">
Spring.addDecoration(new Spring.ValidateAllDecoration({
elementId : 'submit',
event : 'onclick'
}));
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "sex",
event: "onChange",
formId:"customer",
params: {fragments:"body", _eventId: "loadSchools"}}));
</script>
</form:form>
</body>
</html>
答案 0 :(得分:1)
“有效”后您没有任何结束</b>
,但</n>
这些事情有时可能导致像你所拥有的那样奇怪的问题
修复它并再试一次
[编辑]我找到了一个解决方案pb:基本上删除了你选择的装饰和ajax事件并按照这样做:
<tr>
<td><font color=red><form:errors path="sex" /></font><b>Sex:</b></td>
<td><form:select path="sex" id="sex" required="true" data-dojo-type="dijit/form/Select" onchange="Spring.remoting.submitForm('sex', 'customer', {fragments:'body', _eventId: 'loadSchools'}); return false;">
<form:option value="MALE" label="MALE" />
<form:option value="FEMALE" label="FEMALE" />
</form:select>
</td>
</tr>
似乎选择装饰存在一些问题...我会试着看看我是否能找到另一种方式,但我测试了它并且它有效
答案 1 :(得分:0)
我解决了这个问题。我删除了 Spring.AjaxEventDecoration 调用,并将 Spring.ElementDecoration 更改为以下内容:
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "sex",
widgetType : "dijit.form.Select",
widgetAttrs : {
promptMessage : "Enter Sex",
required : true,
onChange : function() {
Spring.remoting.submitForm(
'submit',
'customer',
{_eventId: 'sexchange', fragments:'contents'}
);
return false;
} }}));
</script>
我不是100%清楚为什么Ajax调用不起作用,但我现在让我的项目使用这段代码!