<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to prevent tab switching on validation errors using p:tabView?</title><link>https://answers.axonivy.com/questions/97/how-to-prevent-tab-switching-on-validation-errors-using-p-tabview</link><description>&lt;p&gt;How can I prevent a tab switch using a p:tabView after a form validation on the second tab fails?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/97/how-to-prevent-tab-switching-on-validation-errors-using-p-tabview" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 21 Nov 2013 09:21:11 -0500</lastBuildDate><item><title>Answer by Nikel Weis</title><link>https://answers.axonivy.com/questions/97/how-to-prevent-tab-switching-on-validation-errors-using-p-tabview/98</link><description>&lt;p&gt;It is necessary to use binding and an ajax event whereas the form resides in the RegisterPage:&lt;/p&gt;
&lt;p&gt;XHTML:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;p:layoutUnit position="center"&amp;gt;
    &amp;lt;p:tabView id="mainTabView" binding="#{tabIndexHelper.messagesTab}"&amp;gt;
        &amp;lt;p:ajax event="tabChange" listener="#{tabIndexHelper.onTabChange}" /&amp;gt;
        &amp;lt;p:tab title="Startseite" id="startPage"&amp;gt;
            &amp;lt;ui:include src="HomePage.xhtml" /&amp;gt;
        &amp;lt;/p:tab&amp;gt;
        &amp;lt;p:tab id="registrationPage" title="#{ivy.cms.co('/Translations/Registration/tabTitleRegistration')}" &amp;gt;
            &amp;lt;ui:include src="RegisterPage.xhtml" /&amp;gt;
        &amp;lt;/p:tab&amp;gt;
    &amp;lt;/p:tabView&amp;gt;
&amp;lt;/p:layoutUnit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Backing-Bean:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private TabView messagesTab = new TabView();

    public TabView getMessagesTab () {
        return messagesTab;
    }

    public void setMessagesTab(TabView messagesTab ) {
        this.messagesTab = messagesTab;
    }

    public void onTabChange(TabChangeEvent event) {   
        TabView tabView = (TabView) event.getComponent();

        int activeIndex = tabView.getChildren().indexOf(event.getTab());

        this.messagesTab.setActiveIndex(activeIndex);

    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Maybe there is an easier way (?) - but it worked for me.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nikel Weis</dc:creator><pubDate>Thu, 21 Nov 2013 09:21:11 -0500</pubDate><guid>https://answers.axonivy.com/questions/97/how-to-prevent-tab-switching-on-validation-errors-using-p-tabview/98</guid></item></channel></rss>