JSF两个需要h:inputText(独占或) [英] JSF two required h:inputText (exclusive or)
问题描述
我认为需要2个imputText:如果重视电子邮件,则不需要手机,反之亦然。
我该怎么办?
I would that 2 imputText are required: if email is valued, the mobilephone is not required and vice versa. How can I do?
谢谢。
<h:inputText required="true" id="usEmail" size="20"
value="#{rwUser.usEmail}" />
<h:message for="usEmail" style="color:red" />
<h:outputText value="#{msg.mobilephone}" styleClass="textMessage" />
<h:inputText id="usMobilephone" size="20"
value="#{rwUser.usMobilephone}" />
<h:message for="usMobilephone" style="color:red" />
推荐答案
有几种方式。
-
将
UIInput
组件绑定到视图和第一个组件的必需属性中,检查提交的值在第二个和第二个的必需属性中,检查第一个的值(组件是按照它们在视图中出现的顺序处理)。
Bind the
UIInput
components to the view and in the required attribute of the first, check the submitted value of the second and in the required attribute of the second, check the value of the first (components are namely processed in the order as they appear in the view).
<h:inputText binding="#{usEmail}" ... required="#{empty usMobilePhone.submittedValue}" />
<h:inputText binding="#{usMobilePhone}" ... required="#{empty usEmail.value}" />
检查请求参数映射中是否存在提交的值。
Check the presence of the submitted value in the request parameter map.
<h:inputText binding="#{usEmail}" ... required="#{empty param[usMobilePhone.clientId]}" />
<h:inputText binding="#{usMobilePhone}" ... required="#{empty param[usEmail.clientId]}" />
或者使用硬编码的客户ID:
Or with hardcoded client IDs:
<h:form id="form">
<h:inputText id="usEmail" ... required="#{empty param['form:usMobilePhone']}" />
<h:inputText id="usMobilePhone" ... required="#{empty param['form:usEmail']}" />
使用 OmniFaces < o:validateOneOrMore>
。
<h:inputText id="usEmail" ... />
<h:inputText id="usMobilePhone" ... />
<o:validateOneOrMore components="usEmail usMobilePhone" showMessageFor="@all" />
这篇关于JSF两个需要h:inputText(独占或)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!