0

使用 primefaces p:tabView 动态创建的选项卡无法正确关闭。当我单击选项卡时,勾选关闭所选选项卡。始终关闭第一个选项卡,而不是当前单击的选项卡。我想要的是,关闭被点击的标签。此处仅关闭第一个选项卡,而不是单击的选项卡。

我的 JSF:

:::::::::::
<h:form prependId="false" id="form">

  <p:tabView value="#{deneBean.tabs}" var="tab" id="myTabView" binding="#{deneBean.tabView}">  
    <p:ajax event="tabClose" listener="#{deneBean.closeme(tab)}" update="@form"/>
    <p:tab title="#{tab.title}"  closable="true"   >
      #{tab.content}
    </p:tab>
  </p:tabView>  
  <p:commandButton value="Add Tab" action="#{deneBean.add}" update="@form" />

</h:form>
:::::::::::::::::::::::

我的 Jsf 豆:

@ManagedBean
@ViewScoped
public class DeneBean implements Serializable {

  public DeneBean() {
  }
  private List<NeuTab> tabs;

  @PostConstruct
  public void init() {
      tabs = new ArrayList<NeuTab>();
  }

  public void add() {
    tabs.add(new NeuTab("tab" + tabs.size(), "some content"));
  }

  public void remove(NeuTab tab) {
    tabs.remove(tab);
  }

  public List<NeuTab> getTabs() {
    return tabs;
  }

  public boolean closeme(NeuTab tab) {

    for (int i = 0; i < tabs.size(); i++) {
        NeuTab neuTab = tabs.get(i);
        System.out.println(i + ".list:" + neuTab.getTitle());
    }
    tabs.remove(tab);
    return true;
  }

  TabView tabView = new TabView();

  public TabView getTabView() {
    return tabView;
  }

  public void setTabView(TabView tabView) {
    this.tabView = tabView;
  }
  :::::::::::::::::::

我的班级 NeuTab:

    public class NeuTab {
        private String title;
        private String content;

        public NeuTab(String title, String content) {
            this.title = title;
            this.content = content;
        }

        public String getTitle() {
            return title;
        }

        public String getContent() {
            return content;
        }
    }
4

1 回答 1

0

Try using the TabCloseEvent.

In your bean:

import org.primefaces.event.TabCloseEvent; 

public void closeme(TabCloseEvent event) {    
    tabs.remove(event.getTab());
}  

On the xhtml:

<p:ajax event="tabClose" listener="#{deneBean.closeme}" update="@form" /> 

Also see:

TabView - Closeable

于 2013-07-23T06:40:29.587 回答