[英]JSF 2.1 conditional field validation
我有以下 JSF 2.1 頁
<h:selectOneRadio value="#{userBean.newUser}">
<f:selectItem itemValue="0" itemLabel="new User" />
<f:selectItem itemValue="1" itemLabel="existing User" />
</h:selectOneRadio>
<br />
<h:inputText value="#{userBean.customerId}" id="customerId" />
<h:message for="customerid" />
<br />
<h:inputText value="#{userBean.firstName}" id="firstName" />
<h:message for="fisrtName" />
<br />
<h:inputText value="#{userBean.lastName}" id="lastName" />
<h:message for="lastName" />
<br />
<h:commandButton value="Submit" action="#{userBean.login}" />
這是我的豆子:
public class UserBean {
private String customerId;
private String newUser= "0";
private String firstName;
private String lastName;
// Getters and seeters ommited.
}
我需要通過以下方式驗證此表單:
如果選擇了“新用戶”單選按鈕,則應驗證所有表單輸入。 如果選擇“現有用戶”,我只需要驗證客戶 ID。
我嘗試了 Hibernate 驗證,還通過實現javax.faces.validator.Validator
接口嘗試了自定義驗證器。
我能以某種方式實現這樣的功能嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.