【发布时间】:2013-11-19 11:01:33
【问题描述】:
我正在学习 JSF,在理解 JSF 验证方面需要一些帮助。我正在尝试借助“http://courses.coreservlets.com/”在同一页面中进行手动、隐式和显式验证。 我用下面的验证写了 2 个输入字段。
Customer Name: <h:inputText value="#{bean.customerName}" required="true" />
Account No: <h:inputText value ="#{bean.accountNo}" >
<f:validateLength minimum="10"></f:validateLength>
</h:inputText>
<h:commandButton value="Submit" action="#{bean.actionValidate}"></h:commandButton>
<h:messages globalOnly="true"></h:messages>
public String actionValidate(){
FacesMessage fcMessage = new FacesMessage();
if(getAccountNo().isEmpty() || getAccountNo() == null) {
fcMessage.setSummary("account no empty");
fcContext.addMessage(null, fcMessage);
}
if (fcContext.getMessageList().size()>0)
return null;
else
return "ManualValidationResult";
}
我的理解是字段 1 的 required 属性和 f:validateLength 验证将在 Process & Validation 阶段进行,如果验证失败,生命周期会进入 Render 响应阶段并首先显示错误消息。一旦通过,就应该执行 bean 验证 - 理想情况下,在我的示例中,bean 中的验证不会被执行。但是,我得到了 “客户名 - 验证错误:值是必需的。”如果两个字段都留空。
我填写了名称字段,现在我收到“account no empty”消息,然后如果在 account no 字段中输入了某个值,则会收到“验证错误:长度小于允许的最小值 '5'”。
谁能帮我理解一下流程?
【问题讨论】:
标签: validation jsf