忽略JSF按钮上的验证单击

时间:2014-04-01 04:39:50

标签: jquery jsf richfaces

我有一个重置按钮,当点击它会导致f:转换器和f:validate被触发,这是有意义的,因为它是为了清除字段。

我正在阅读this article,它演示了当我使用immediate="true"点击我的“重置”按钮时如何防止验证出现,这非常有效...仅适用于第一个重置按钮。

但是,我有多个重置按钮并将它们设置为具有属性immediate="true",但它似乎只能在第一个重置按钮上工作,我仍然会显示错误消息,显示其他3个重置的无效数据的按钮。

如果需要布局背景,我的XHTML看起来像这样:

<a4j:outputPanel ajaxRendered="true">
    <h:messages globalOnly="true" showDetail="false" infoClass="info" warnClass="warning" errorClass="error" fatalClass="fatal" />
        <h:message for="field1" errorClass="error"></h:message>
        <h:message for="field2" errorClass="error"></h:message>
        <h:message for="field3" errorClass="error"></h:message>
        <h:message for="field4" errorClass="error"></h:message> 
</a4j:outputPanel>
<h:form id="form1" rendered="true">
    <h:panelGrid columns="8">
        <h:outputText value="#{bundle.label}" />
        <h:inputText id="field1" size="18" maxlength="18" immediate="true"
            value="#{myBean.myField1}">
            <f:converter converterId="LongConverter" />
            <f:validateLength minimum="1" maximum="18"></f:validateLength>
        </h:inputText>
    </h:panelGrid>
    <h:commandButton id="reset1" type="submit" value="#{bundle.label}" onclick="resetField()"
        styleClass="button" action="#{myBean.reset1}" immediate="true" />
</h:form>
<h:form id="form2" rendered="true">
    <h:panelGrid columns="8">
        <h:outputText value="#{bundle.label}" />
        <h:inputText id="field2" size="18" maxlength="18" immediate="true"
            value="#{myBean.myField2}">
            <f:converter converterId="LongConverter" />
            <f:validateLength minimum="1" maximum="18"></f:validateLength>
        </h:inputText>
    </h:panelGrid>
    <h:commandButton id="reset2" type="submit" value="#{bundle.label}" onclick="resetField()"
        styleClass="button" action="#{myBean.reset2}" immediate="true" />
</h:form>
<h:form id="form3" rendered="true">
    <h:panelGrid columns="8">
        <h:outputText value="#{bundle.label}" />
        <h:inputText id="field3" size="18" maxlength="18" immediate="true"
            value="#{myBean.myField3}">
            <f:converter converterId="LongConverter" />
            <f:validateLength minimum="1" maximum="18"></f:validateLength>
        </h:inputText>
    </h:panelGrid>
    <h:commandButton id="reset3" type="submit" value="#{bundle.label}" onclick="resetField()"
        styleClass="button" action="#{myBean.reset3}" immediate="true" />
</h:form>
<h:form id="form4" rendered="true">
    <h:panelGrid columns="8">
        <h:outputText value="#{bundle.label}" />
        <h:inputText id="field4" size="18" maxlength="18" immediate="true"
            value="#{myBean.myField4}">
            <f:converter converterId="LongConverter" />
            <f:validateLength minimum="1" maximum="18"></f:validateLength>
        </h:inputText>
    </h:panelGrid>
    <h:commandButton id="reset4" type="submit" value="#{bundle.label}" onclick="resetField()"
        styleClass="button" action="#{myBean.reset4}" immediate="true" />
</h:form>

我真的不知道问题是关于按钮还是多个表单共享的ajax?当有多个重置按钮/字段如上所述时,有人能告诉我正确的方法吗?

修改 我尝试从Reset按钮中删除所有immediate = true,当然,单击Reset按钮时会显示错误消息。但是我注意到它只在最后三个表单上重置按钮,而不是在第一个...?

我希望这可以让知道导致这个问题的人更深入了解

1 个答案:

答案 0 :(得分:0)

您在输入字段上有immediate="true",这也会使它们得到处理。