1

我正在使用 Spring 和 dijit 组件从我的模型中的枚举中呈现选项列表:

<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({
                        elementId : "selection",
                        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>

当 Javascript 关闭时,来自 btnSelect 的帖子成功地将所选项目转换为服务器端的枚举。也就是说,我的转换服务显示此消息:

DEBUG: org.springframework.binding.mapping.impl.DefaultMapping - Adding mapping result [Success@15fddb33 mapping = parameter:'selection' -> selection, code = 'success', error = false, originalValue = 'IPSUM', mappedValue = 'IPSUM']

但是,当 Javascript 打开并且帖子通过 XHR 时,枚举转换失败。显示此消息的转换服务:

DEBUG: org.springframework.binding.mapping.impl.DefaultMapping - Adding mapping result [TargetAccessError@7b7d8769 mapping = parameter:'selection' -> selection, code = 'typeMismatch', error = true, errorCause = org.springframework.binding.expression.ValueCoercionException: Value could not be converted to target class; is a suitable type converter registered?, originalValue = 'selection', mappedValue = [null]]

如果他们都使用相同的转换服务,我不明白为什么会发生这种情况。我是否必须设置特殊配置才能使 AJAX 调用绑定到枚举?

4

0 回答 0