【问题标题】:primefaces p:tabView dynamic tabs does not close properlyprimefaces p:tabView 动态选项卡未正确关闭
【发布时间】:2013-07-21 02:26:45
【问题描述】:

使用 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;
        }
    }

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    尝试使用 TabClos​​eEvent。

    在你的 bean 中:

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

    关于xhtml:

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

    另见:

    TabView - Closeable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-18
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 2011-05-02
      相关资源
      最近更新 更多