0

我正在使用 Spring 3.0.5、Webflow 2.3.0 和 Spring JS 进行装饰。

我的一种形式具有以下代码:

<form:select path="selection">
    <form:option value="" label="Please select"></form:option>
    <form:options></form:options>
</form:select>

<noscript>
 <button id="btnSelect" type="submit" name="_eventId_dropDownSelectionChange">Select</button>
</noscript>

<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
    widgetType : "dijit.form.Select",
    widgetAttrs : {
        forceWidth : true,
        missingMessage : "<s:message code="NotEmpty" />",
    }
}));

Spring.addDecoration(new Spring.AjaxEventDecoration({
    elementId : "selection",
    formId : "templateModel",
    event : "onChange",
    params : {  _eventId: "dropDownSelectionChange" }
})); 
</script>

目的是根据下拉列表中选择的内容呈现表单的第二部分。这可以通过下拉列表的 onChange 上的 AJAX 调用来实现,或者在 noscript 的情况下 - 按下“选择”按钮。

事情的无脚本方面有效。我在下拉列表中选择了一些东西,按“选择”,然后刷新时呈现表单的其余部分。

但是,AJAX 调用在其请求中没有刚刚选择的值。就好像 AJAX 调用发生在 Dijit 组件更新其表示之前。这些组件是否与我使用它们的方式兼容?

如果满足以下条件,我可以让它工作:

  1. 我没有将组件装饰为 Dijit 组件,而只是使用 onclick AJAX 装饰的普通下拉菜单。
  2. 我将 AJAX 调用放在按钮上而不是 Dijit onChange 上
4

1 回答 1

0

面临同样的问题,解决方法是在隐藏字段中设置选定的值,Spring.AjaxEventDecoration 负责其余的工作。

                <input id="vehicleType" name="vehicleType" type="hidden" />
                    <select id="selectVehicle">
                        <c:forEach var="vehicle" items="${vehicleTypes}">
                            <option value="${vehicle.type}"><fmt:message key="${vehicle.description}" /></option>
                        </c:forEach>
                    </select>
                </p>
                <script type="text/javascript">
                    Spring.addDecoration(new Spring.ElementDecoration({
                        elementId : 'selectVehicle',
                        widgetType : "dijit.form.Select",
                        widgetAttrs : {
                            value : "${vehicleType}",
                            onChange : function(newValue){
                            document.getElementById('vehicleType').value=dijit.byId('selectVehicle').get('value');}
                        }                           
                    }));
                    Spring.addDecoration(new Spring.AjaxEventDecoration({
                        elementId : "selectVehicle",
                        formId : "quote",
                        event : "onChange",
                        params : {
                            _eventId : "dropDownVehicleSelectionChange",
                            fragments : "body"

                        }
                    }));
                </script>
于 2011-09-26T00:17:42.877 回答