问题
请参见以下JSF示例:
<h:inputSecret id="password" value="#{user.password}"
size="20" required="true" label="Password">
<f:validateRegex pattern="((?=.*\d).{6,20})" />
</h:inputSecret>
<h:message for="password" style="color:red" />
<h:commandButton value="Cancel" action="cancel" />
<h:commandButton value="Submit" action="result" />
如果单击“取消”按钮,将触发密码验证并停止您在取消页面上的操作,这是没有意义的。 有什么方法可以绕过JSF中的验证?
解
要跳过验证,请在“取消”按钮上添加一个即时=“ true”属性。
<h:inputSecret id="password" value="#{user.password}"
size="20" required="true" label="Password">
</h:inputSecret>
<h:message for="password" style="color:red" />
<h:commandButton value="Cancel" immediate="true" action="cancel" />
<h:commandButton value="Submit" action="result" />