简体   繁体   English

selectOneMenu上是否只接受true?

[英]Does required on selectOneMenu only accept true?

I have this selectOneMenu that asks for something, the default value is empty, because people need to think about the question and actually needs to fill it in. 我有这个selectOneMenu要求的东西,默认值是空的,因为人们需要考虑问题,实际上需要填写它。

<h:selectOneMenu id="fileSecurity" value="#{flowScope.application.fileSecurity}" required="true" >  
    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>  
    <f:selectItem itemLabel="ja" itemValue="true" />  
    <f:selectItem itemLabel="nee" itemValue="false" />     
</h:selectOneMenu>

This is what i have, now when you fill in the empty value it gives: "managementTabs:ApplicationManagementForm:fileSecurity : Needs to be filled in." 这就是我所拥有的,现在当你填写它给出的空值时:“managementTabs:ApplicationManagementForm:fileSecurity:需要填写。” wich is correct. 这是对的。

When i click yes or the true value it accepts the anwser. 当我单击是或真值时,它接受anwser。

But when i click no or false it gives: "managementTabs:ApplicationManagementForm:fileSecurity: Validation Error: Value is not valid" 但是当我点击no或false时,它会给出:“managementTabs:ApplicationManagementForm:fileSecurity:Validation Error:Value is not valid”

  • Why does Jsf2.0 only accept true as the valid awnser and not false? 为什么Jsf2.0只接受true作为有效的awnser而不是false?
  • Is there a way around this? 有没有解决的办法? Or do i have to write a custom validator? 或者我是否必须编写自定义验证器?

It seems that a submitted value of false is conflicting with the empty string value of noSelectionOption in some way. 似乎提交的false值以某种方式与noSelectionOption的空字符串值冲突。 The following entries for the 1st item works fine: 第1项的以下条目正常:

<f:selectItem itemLabel="" itemValue="" />  

and

<f:selectItem itemLabel="" noSelectionOption="true" />

and

<f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />

I only don't understand why. 我只是不明白为什么。 It's illogical. 这是不合逻辑的。 To find the real answer, I would need to run the debugger. 要找到真正的答案,我需要运行调试器。


Update : I debugged and found the culprit in the SelectUtils#valueIsNoSelectionOption() (Mojarra). 更新 :我调试并在SelectUtils#valueIsNoSelectionOption() (Mojarra)中找到了罪魁祸首。 The empty string of the noSelectionOption get coerced to boolean false instead of Boolean null and hence the comparison with the submitted value is valid and hence the selected value is invalid. noSelectionOption的空字符串被强制转换为boolean false而不是Boolean null ,因此与提交的值的比较是有效的,因此所选值无效。 This is "by design". 这是“按设计”。 You really need to explicitly specify an itemValue="#{null}" . 您确实需要显式指定itemValue="#{null}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM