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

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

问题描述

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

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>

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

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"时,它应保留在您所位于的选项卡上.另外,请确保为标签页添加

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天全站免登陆