如果字段评估失败,如何保持在同一个选项卡上 [英] How to stay on same Tab if field evalution failed

查看:17
本文介绍了如果字段评估失败,如何保持在同一个选项卡上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有主页标签和验证标签.如果用户输入有效,我喜欢验证用户输入并切换回主页选项卡,否则留在验证选项卡上.此时,即使我点击提交按钮后用户输入无效,它也会切换回主页选项卡.

I have home tab and Validation tab. I like to validate user input and switch back to home tab if the user input is valid, otherwise stay on validation tab. At this point, it is switching back to home tab even for invalid user input after I click on submit button.

index.xhtml

index.xhtml

<p:tabView>
    <p:tab title="Home" titleStyleClass="repo">
        <h:panelGrid columns="2" cellpadding="10">
            <h:form>
             /****home table code here***/
            </h:form>
        </h:panelGrid>
    </p:tab>

    <p:tab title="Validation">
        <h:form>
            <h:panelGrid id="grid" columns="4" cellpadding="5">
                <h:outputLabel for="number" value="number:" />
                <p:inputText id="number" value="#{validationView.number}"
                    label="Number">
                    <f:validateDoubleRange minimum="100" maximum="200" />
                </p:inputText>
            </h:panelGrid>
        <p:commandButton value="Submit"
                actionListener="#{controller.saveA}" ajax="false"
                icon="ui-icon-check" validateClient="true" style="float-right" />
        </h:form>
    </p:tab>
</p:tabView>

我确定,我在这里遗漏了一些东西,我不知道如何取回 primefaces 中特定选项卡上的验证结果并基于此设置选项卡切换.

I am sure, I am missing something here, I don't know how to get back the validation result on a particular tab in primefaces and set tab switching based on that.

*我使用的是 primefaces 5.1

*I am using primefaces 5.1

推荐答案

您的提交按钮上有 ajax="false".而且由于您不使用 tabView 的 activeIndex,它总是会切换回第一个选项卡.使用 ajax="true"(默认)而不是 false.删除 ajax="false" 时,它应该保留在您所在的选项卡上.还要确保你给你的标签一个widgetVar,比如

You have ajax="false" on your submit button. And since you do not use the activeIndex of the tabView, it wil always switch back to the first tab. Use ajax="true" (the default) instead of false. When removing the ajax="false", it should stay at the tab you are at. Also make sure you give your tab a widgetVar like

<p:tabView widgetVar="tabWidget">
    ...
</p:tabView>

那么你有两个选择:

  1. 在commandButton的oncomplete事件中,检查validationErrors,如果没有发生,切换到第一个标签

  1. in the oncomplete event of the commandButton, check for validationErrors and if non occured, switch to the first tab

<p:commandButton value="Submit"
    actionListener="#{controller.saveA}"
    icon="ui-icon-check" validateClient="true" style="float-right"
    oncomplete="if (args &amp;&amp; !args.validationFailed) tabWidget.select(0);"
/>

查看 & 转义的原因: 在发生验证错误后保持 p:dialog 打开提交

See for the why of the escaping of the & : Keep p:dialog open when a validation error occurs after submit

你也可以使用如果你的监听器被调用,你就知道验证成功了.因此,在监听器中,您可以使用 remoteContext 并使其执行选项卡切换

You could also use the fact that IF your listener is called, you know that validation succeded. So in the listener you could use the remoteContext and make that execute the tab switch

RequestContext.getCurrentInstance().execute("tabWidget.select(0)");

这篇关于如果字段评估失败,如何保持在同一个选项卡上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆