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
(suspended)
accept rate: 57%


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

XHTML:

<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>
        <p:tab id="registrationPage" title="#{ivy.cms.co('/Translations/Registration/tabTitleRegistration')}" >
            <ui:include src="RegisterPage.xhtml" />
        </p:tab>
    </p:tabView>
</p:layoutUnit>

Backing-Bean:

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

    }

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

link

answered 21.11.2013 at 09:21

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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

Tags:

×51

Asked: 21.11.2013 at 09:16

Seen: 10,247 times

Last updated: 21.11.2013 at 09:21