tabView: Attribute "activeIndex" bound to MB buggy?

UI Components for JSF
Post Reply
jenscb
Posts: 21
Joined: 03 Apr 2010, 20:15

25 Jan 2011, 23:27

Hi there,

I have a problem using the tabView Component:
I'm trying to store the active, displayed tab in a managed bean, so it can withstand an update of p:poll. Otherwise upon every poll update the first tab gets selected.
I tried binding the activeIndex to a managed bean property, but that didn't work out: Using this facelets page and this managed bean, switching the tab never gets reported to the managed bean.

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

26 Jan 2011, 00:07

Hi there,

could you try this?

Code: Select all

 <h:form>
            <p:poll update="myTabView"
                   interval="10"/>
       
        <p:tabView id="myTabView" dynamic="true" cache="false" onTabChangeUpdate="@this"
                  activeIndex="#{beanTabView.activeIndex}">
            <p:tab title="foo">
                foofoofoo
            </p:tab>
            <p:tab title="bar">
                barbarbar
            </p:tab>
        </p:tabView>
 </h:form>
I use Tabview with activeIndex without any problem but ive never used with poll. Later i ll try the above code but it should work, i hope it helps.
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

26 Jan 2011, 02:38

Just putting on the same form solves your problem, tested it here right now.
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

jenscb
Posts: 21
Joined: 03 Apr 2010, 20:15

26 Jan 2011, 19:53

Thanks so much :) That really did the trick, and I even hadn''t had to bind the activeIndex to the MB.
But even though it works for me now, I wonder if it's a bug, because the MB never got a message about selecting another active tab?

And another possible bug thing: Actually these tabs contain a datatable with sortable columns: excerpt Sorting works perfectly, but upon the poll-update the tiny little arrow-Icons indicating the sort order get reset. I don't mind, just wanted to let you know :-)


Again, thanks a lot, wish I could somehow return the favour :-)

matei123
Posts: 6
Joined: 09 May 2011, 14:25

18 May 2011, 14:08

I tried to do a similar thing with PrimeFaces 3.0.M1 and it did not work. It seems the getter of the MB is invoked first and then the setter leaving the activeIndex in MB to the initial value. I think this is a bug which need to be resolved. Meanwhile I come with the below work-around. Hope it will help somebody.

The view:

Code: Select all

        <p:tabView id="myTabView"
            tabChangeListener="#{tabViewBean.onTabChange}"
            activeIndex="#{tabViewBean.activeIndex}">

            <p:tab id="tab_0" title="First Tab">
            </p:tab>
            <p:tab id="unregieterMac_tab_1" title="Second Tab">
            </p:tab>
        </p:tabView>
The Managed bean:

Code: Select all

@ManagedBean(name="tabViewBean")
@ViewScoped
public class TabViewBean {
    
    private int activeIndex = 0;

    /**
     * Sets the activeIndex (0 based) according to the id of the selected tab;
     * the id of the selected tab should be in the following format: <tabname>_tab_<index>;
     * <index> is 0 based and will be used to set the activeIndex of the tab view 
     * 
     * @param event
     */
    public void onTabChange(TabChangeEvent event) {
        String activeTabId = event.getTab().getId();
        String tokens[] = activeTabId.split("_");
        if (tokens.length >= 2 && "tab".equals(tokens[tokens.length-2])) {
            try {
                activeIndex = Integer.parseInt(tokens[tokens.length-1]);
            } catch (NumberFormatException nfe) {
                // the tab id is not in understood format  
            }
        }
    }  
    
    public int getActiveIndex() {
        return activeIndex;
    }

    public void setActiveIndex(int activeIndex) {
        this.activeIndex = activeIndex;
    }

}

hoffmann05
Posts: 1
Joined: 03 Jan 2012, 22:23

03 Jan 2012, 22:33

Code: Select all

 
public void onTabChanged(TabChangeEvent event) {       
        this.tabSelected = event.getTab().getParent().getChildren().indexOf(event.getTab());  
}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 47 guests