How can I prevent a tab switch using a p:tabView after a form validation on the second tab fails?

asked 21.11.2013 at 09:16

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

It is necessary to use binding and an ajax event whereas the form resides in the RegisterPage:


<p:layoutUnit position="center">
    <p:tabView id="mainTabView" binding="#{tabIndexHelper.messagesTab}">
        <p:ajax event="tabChange" listener="#{tabIndexHelper.onTabChange}" />
        <p:tab title="Startseite" id="startPage">
            <ui:include src="HomePage.xhtml" />
        <p:tab id="registrationPage" title="#{'/Translations/Registration/tabTitleRegistration')}" >
            <ui:include src="RegisterPage.xhtml" />


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());



Maybe there is an easier way (?) - but it worked for me.


answered 21.11.2013 at 09:21

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 21.11.2013 at 09:16

Seen: 9,101 times

Last updated: 21.11.2013 at 09:21