PrimeFaces在“取消"按钮上禁用验证 [英] PrimeFaces disable validation on cancel button
问题描述
在一种形式中,我有一些带有两个commandButton的inputText,一个用于接受,一个用于取消.如何仅对取消按钮禁用验证?
In a form I have some inputText with two commandButton, one for accept and one for cancel. How can disable validation only for cancel button?
<h:form id="detailsForm">
<p:inputText id="editUsername" value="#{userController.editUser.usrUsername}" />
<p:inputText id="editFirstName" value="#{userController.editUser.usrFirstName}" />
<p:inputText id="editLastName" value="#{userController.editUser.usrLastName}" />
<p:commandButton value="Accept" update=":detailsForm" actionListener="#{userController.onDetailsEditAccept}" />
<p:commandButton value="Cancel" update=":detailsForm" actionListener="#{userController.onDetailsEditCancel}" />
</h:form>
我已经尝试在字段上插入required="false"
,但没有成功.
我也尝试在字段上插入<f:validateBean disabled="true" />
,但没有成功.
I already tried to insert required="false"
on fields but it didn't worked.
I tried also to insert <f:validateBean disabled="true" />
on fields and it didn't worked.
推荐答案
在取消commandButton
中使用属性immediate="true"
.通过跳过应用请求值,过程验证和更新模型值阶段,这将跳过表单的整个处理过程.>
Use the attribute immediate="true"
in your cancel commandButton
. This will skip the entire processing of the form, tough, by skipping the Apply Request Values, Process Validations and Update Model Values phases.
<p:commandButton value="Cancel" update=":detailsForm" actionListener="#{userController.onDetailsEditCancel}" immediate="true"/>
这篇关于PrimeFaces在“取消"按钮上禁用验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!