Spring JS Ajax 调用 - 枚举数据绑定无法转换但字符串有效
我使用带有 dijit 组件的 Spring 从模型中的枚举呈现选项列表:
<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 调用可以绑定到枚举?
I'm using Spring with dijit components to render an option list from an enum in my model:
<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>
When Javascript is off, the post from btnSelect successfully converts the selected item to an enum on the server side. That is, my conversion service shows this message:
DEBUG: org.springframework.binding.mapping.impl.DefaultMapping - Adding mapping result [Success@15fddb33 mapping = parameter:'selection' -> selection, code = 'success', error = false, originalValue = 'IPSUM', mappedValue = 'IPSUM']
However, when Javascript is on and the post goes over XHR, the enum conversion fails. Conversion service showing this message:
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]]
I don't understand why this is happening if they're both using the same conversion service. Do I have to set up a special configuration so that AJAX calls can bind to enums?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论