JSF Dropdowns - 强制执行非默认值进行验证
我们有使用默认值“Select One..”的 JSF 下拉列表,但我们不希望 JSF 验证器在保存时接受此值作为可接受的值。
那么除了/或代替Required =“true”,有什么办法可以做到这一点?
示例值:
"select one.."
"cat"
"dog"
只有“cat”或“dog”应该通过验证。
We have JSF dropdowns that use a default value of "Select One..", but we do not want our JSF validator to accept this as an accpetable value on save.
so beyond/or in place of Required="true", is there any way to do this?
example values:
"select one.."
"cat"
"dog"
Only "cat" or "dog" should pass validation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎已将“选择一个...”设置为标签和值。为了触发需求验证器,该值必须为
null
。您需要将“选择一个...”设置为标签,并将null
设置为值。所以在视图中:
或在模型中:
You seem to have set "Select one..." as both the label and value. In order to trigger the requireness validator, the value has to be
null
. You need to set "Select one..." as label andnull
as value.So in view:
or in model: