强制复选框JSF [英] mandatory checkboxes JSF
问题描述
我有3个复选框,因此我有3个不同的ID。我需要至少一个复选框由用户选中。我已经为第一个ID定义了错误消息,因此如果用户不选中所有3个复选框,他将看到我的错误消息,第一个复选框将被标记为黄色。
I have 3 checkboxes, so I have 3 different IDs. I need at least one checkbox checked by the user. I have defined an error message only for the first ID, so if the user leaves all 3 checkboxes unchecked, he will see my error message and the first checkbox will be marked yellow.
现在,当没有选中时,我想将所有3个复选框标记为黄色。这可能与每个ID的3个错误消息。但不必要的副作用是,用户然后看到3个错误消息。我只想要一个错误消息和3个黄色复选框。这可能在JSF?
Now I want to mark all 3 checkboxes yellow when none is checked. This is possible with 3 error messages for each ID. But the unwanted side effect is that the users then sees 3 error messages. I want only one error message and 3 yellow checkboxes. It this possible in JSF?
推荐答案
这基本上有两个解决方案:
This has basically 2 solutions:
-
使用单一
< h:selectManyCheckbox>
,而不是< h:selectBooleanCheckbox>
es,以便您可以简单地在其上设置required =true
:
<h:selectManyCheckbox ... required="true">
...
</h:selectManyCheckbox>
使用 < o:validateOneOrMore>
.orgrel =nofollow> OmniFaces :
<h:selectBooleanCheckbox id="one" ... />
<h:selectBooleanCheckbox id="two" ... />
<h:selectBooleanCheckbox id="three" ... />
<o:validateOneOrMore components="one two three" />
这篇关于强制复选框JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!