Validation 在表单中执行commandButton,但存在验证错误

Validation 在表单中执行commandButton,但存在验证错误,validation,jsf,facelets,Validation,Jsf,Facelets,我想在backingbean中执行一个函数,在有验证错误的表单中使用CommandButton 使用代码示例,我希望调用函数“resiCon.cancel()”,而不管表单上是否存在验证错误 你能帮我吗 <h:form id="mainform"> .... <h:inputText value="#{resiCon.code"> <f:validateLongRange minimum="1" /> &l

我想在backingbean中执行一个函数,在有验证错误的表单中使用CommandButton

使用代码示例,我希望调用函数“resiCon.cancel()”,而不管表单上是否存在验证错误

你能帮我吗

<h:form id="mainform">

    ....      
    <h:inputText value="#{resiCon.code">
        <f:validateLongRange minimum="1" />
    </h:inputText>

    <h:commandButton id="save" value="Save" update="mainform" action="#{resiCon.save()}"/>
    <h:commandButton id="cancel" value="Cancel" update="mainform" action="#{resiCon.cancel()}"/>

</h:form>

....      
多谢各位


Tomcat v7.0、Myfaces 2.1.5、Spring 3.1.0至少有两种方式:

  • immediate=“true”
    添加到取消按钮。这将跳过所有没有此设置的输入字段

    <h:commandButton id="cancel" ... immediate="true" />
    
  • 上使用
    immediate=“true”
    。这里有一篇文章专门介绍取消按钮和
    immediate=“true”
    属性:

    <h:commandButton id="cancel" ... >
        <f:ajax execute="@this" render="@all" />
    </h:commandButton>