我想要两个必需的消息:selectOneMenu组件,即当用户提交表单时,如果其中一个选择值不为null,则应调用bean方法,否则(两者都为null):我应该告诉他至少选择一个,这可能吗?或者我必须使用JS。 提前谢谢,
答案 0 :(得分:2)
我会使用OmniFaces validateOne验证器或validateOneOrMore如果允许填充两者。
他们网站的代码示例:
<h:form>
<h3>Please fill out only one of two fields</h3>
<o:validateOne id="one" components="foo bar" />
<h:panelGrid columns="3">
<o:outputLabel for="foo" value="Foo" />
<h:inputText id="foo" />
<h:message for="foo" />
<o:outputLabel for="bar" value="Bar" />
<h:inputText id="bar" />
<h:message for="bar" />
<h:panelGroup />
<h:commandButton value="submit">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:panelGroup>
<h:message for="one" />
<h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
</h:panelGroup>
</h:panelGrid>
</h:form>