【发布时间】:2016-10-03 18:45:39
【问题描述】:
我有一个 PrimeFaces 应用程序,我想让两个输入文本字段互斥:用户应该填写其中一个字段,但不能同时填写。
在以下示例中,用户可以通过电话号码或电子邮件搜索联系人。
<h:form>
<h:outputLabel>Phone Number:
<h:inputText id="phoneInput" value="#{contactSearch.phone}"
disabled="#{not empty contactSearch.email}">
<p:ajax event="keyup" update="emailInput"/>
</h:inputText>
</h:outputLabel>
<h:outputLabel>Email Address:
<h:inputText id="emailInput" value="#{contactSearch.email}"
disabled="#{not empty contactSearch.phone}">
<p:ajax event="keyup" update="phoneInput"/>
</h:inputText>
</h:outputLabel>
<!-- Possibly other fields... -->
<h:commandButton value="Search" action="#{contactSearch.search}"/>
</h:form>
这是正确的方法吗?我担心:
- 可能的“死锁”问题,两个字段最终都被禁用
- 当我只想更新输入字段的
disabled状态时,在 Ajax 请求中提交和/或验证的整个表单 - 缺少一些完成所有工作的预定义 PrimeFaces 控件:)
【问题讨论】:
标签: validation jsf jsf-2 primefaces