用于 null 值的 Spring 格式化程序
我的视图中有一个选择控件,我想将“请选择一个项目”项目“绑定”或“格式化”为我的支持表单对象中的空值。 这可能吗?因为我知道一些传统的格式不能正常工作。 相反,我看到了一个在类 GenericConversionService 中进行更改并使用该类而不是原始类的示例。 (不幸的是,我再也找不到它了)
这是当我从格式化程序类返回空值时的异常:
org.springframework.core.convert.ConversionFailedException: Unable to convert value "-1" from type 'java.lang.String' to type 'com.tesisutn.restsoft.dominio.articulo.Marca'; nested exception is java.lang.NullPointerException
提前非常感谢!
I have a select control in my view and i want to "bind" or "format" the item "Please select an item" to a null value in my backing form object.
Is that possible? because i know that making some traditional formatting doesn't work properly.
Instead i saw an example of making changes in class GenericConversionService and using that class instead of the original. (unfortunately i can't find it anymore)
This is the exception when i return a null value from my formatter class:
org.springframework.core.convert.ConversionFailedException: Unable to convert value "-1" from type 'java.lang.String' to type 'com.tesisutn.restsoft.dominio.articulo.Marca'; nested exception is java.lang.NullPointerException
Thanks a lot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的表单似乎正在发送
-1
来指示“请选择一个项目”已被选中。您可以尝试的第一件事就是发送注释。然后绑定(当表单发送到服务器时)将起作用,相应的命令对象字段将为空。
如果这不适合您(例如因为您使用dojo),那么您需要实现自己的属性编辑器 或 对话 (Spring 3.0)
It looks like your form is sending a
-1
to indicate that "Please select an item" is selected.First thing you can try is to send noting. Then the binding (when the form is send to the server) will work, the according command object field will be null.
If this is no option for you (for example because you use dojo), then you need to implement your own property editor or conversation (Spring 3.0)