单击按钮时更改选项卡而不更新tabView

时间:2015-09-29 13:23:06

标签: jsf primefaces tabview

我想通过单击commandButton来更改选项卡。我在我的bean上控制activeIndex并对tabView组件进行更新。一切正常。

我的问题是我想更改activeIndex而不需要对tabView进行更新,因为该组件的更新有点慢。

是否可以通过单击按钮更改选项卡,并在不更新的情况下执行此操作?

这是我的实际代码。

TabView组件

 <p:tabView id="tvFoo" dynamic="true" activeIndex="#{fooBean.activeIndex}">


       <p:tab title="Title" id="someTab">                                         
          <ui:include src="someTabName.xhtml" />          
       </p:tab>

       <p:tab title="Title2" id="anotherTab">                                         
          <ui:include src="anotherTabName.xhtml" />       
       </p:tab>

</tabView>

在someTabName.xhtml

<p:commandButton value="go to anotherTab"  actionListener="#{fooBean.tabChange('anotherTabName')}" />

fooBean,它控制标签更改

public void tabChange(String tabId) {    
        switch (tabId) {    
        case "anotherTabName":                                      
            activeIndex = 2;
            RequestContext.getCurrentInstance().update("tvFoo"); //here is the line that I don't want to call                    
        break;
    }

我可以删除该行RequestContext.getCurrentInstance().update("tvFoo");吗?当然,如果只是删除,标签不会更改。

要恢复,基本上我想要更改打开的标签。我认为我可以手动调用changeTab事件,但我不知道怎么做。

2 个答案:

答案 0 :(得分:1)

为什么不通过命令按钮对tabview组件进行更新? 我认为你必须在某处进行更新,否则,tabview应该如何注意到这一变化?而且,据我所知,更新功能并不慢。

要获取tabview的当前索引,您可以使用Faces Context:

TabView tabView = FacesContext.getCurrentInstance().getViewRoot().findComponent(aComponentId); 

tabView上,您可以单独获取并设置有效标签。

我希望这有帮助,祝你好运!

答案 1 :(得分:-1)

您是否尝试过使用向导组件?我相信你正在寻找的行为类似于这个primefaces向导。

http://www.primefaces.org/showcase/ui/panel/wizard.xhtml

相关问题