提交导致“验证错误:值无效”
朋友们,我在网络开发时再次陷入困境,我向用户提供多个选择列表以选择多个选项。 JSF 页面的片段
<h:selectManyListbox id="associatedAS" value="#{maintainForm.selectedAS}">
<s:selectItems value="#{maintainForm.associatedAS}" var="as" label="#{as.name}" />
<rmc:asConverter />
</h:selectManyListbox>
,但问题是提交页面时我在控制台上收到错误
sourceId=maintainForm:linkedAS[severity=(错误 2),summary=(maintainForm:linkedAS:验证错误:值无效),detail=(maintainForm:linkedAS:验证错误:值无效)]
我无法弄清楚为什么会发生这种情况,我在列表中显示的项目不是字符串,所以我编写了转换器“asConverter”,用于将其他对象的值转换为字符串,反之亦然。另外,我在标签“#{maintainForm.selectedAS}”中给出的值是列表类型(selectedAS)。
任何形式的帮助表示赞赏。
谢谢。
Pals, I got stuck again while my web development, I am providing multiple selection list to user for selecting many option. A Fragment of JSF Page
<h:selectManyListbox id="associatedAS" value="#{maintainForm.selectedAS}">
<s:selectItems value="#{maintainForm.associatedAS}" var="as" label="#{as.name}" />
<rmc:asConverter />
</h:selectManyListbox>
but the problem is that when submit the page I am getting error on console
sourceId=maintainForm:associatedAS[severity=(ERROR 2), summary=(maintainForm:associatedAS: Validation Error: Value is not valid), detail=(maintainForm:associatedAS: Validation Error: Value is not valid)]
I am not able to figure out why this is happening, the item I am displaying in list is not string so I have written converter 'asConverter' for converting values from other objects to string and vice-versa. Also the Value I given above in tag ' #{maintainForm.selectedAS} ' is of type List (selectedAS).
Any kind of help appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我和拉维·尼卡姆有同样的问题。实现了 Equals 方法和转换器,并且它与
selectOneMenu
一起工作得很好,但它与selectManyListBox
一起给出了一个很好的验证错误:值无效
>。经过几个小时的搜索,我找到了解决方案。
selectManyListbox
基于javax.faces.component.UISelectMany
。UISelectMany
的 javadoc 说:所以此列表中的最后一点引起了我的问题:“不要转换值”。
我已在 faces-config.xml 中指定,
在
h:selectManyListbox
中,我没有指定转换器。我通过添加到 faces-config.xml
并将属性
converter="myConv"
添加到h:selectManyListbox
标记解决了该问题。I had the same problem as Ravi Nikam. Equals method and converter are implemented, and it works fine with a
selectOneMenu
, but it gives a niceValidation Error: Value is not valid
with aselectManyListBox
.After searching for some hours, I found a solution.
The
selectManyListbox
is based onjavax.faces.component.UISelectMany
.The javadoc of the
UISelectMany
says:So the last point in this list caused my problem: "Do not convert the values".
I had specified in faces-config.xml
In the
h:selectManyListbox
I had no converter specified.I solved the problem by adding to faces-config.xml
and by adding the attribute
converter="myConv"
to theh:selectManyListbox
tag.当您向页面发送一些值,然后发送的部分或全部原始值被修改,或者在客户端上添加一些新值时,就会出现此问题。正如您已经知道的,JSF 在服务器或客户端上保留其视图状态,取决于您如何配置它,因此它在提交时使用该状态来验证组件。在您的情况下,它发现发送到客户端的值不再相同。因此你最终会得到这个错误。
如果您使用自定义转换器,正如我在转换器页面上所描述的那样,您必须为您尝试转换的对象提供一个有效的 equals 方法。如果您尝试使用默认的 equals 方法或弄乱实现,则对象将无法正确转换,从而导致相当不直观的错误消息:“验证错误:值无效”。 - 参考:crazysquirrel.com
另一个类似的建议。
This problem occurs when you send some values to the page, and then some or all of the original values sent got modified, or some new values got added on the client. As you already know, that JSF keep its view state on the server or client, depends how you configured it, so it validates the component using that state on submit. In your case it found out that the values sent to the client are no more the same. Hence you end up getting this error.
If you are using a custom converter, as I describe on the converters page, you have to provide a working equals method for the object that you are trying to convert to and from. If you attempt to use the default equals method or fluff the implementation the object won't convert correctly leading to the rather non-intuitive error message: "Validation Error: Value is not valid". - ref: crazysquirrel.com
Another similar suggestion.