dynamically created tabs with primefaces p:tabView does not close properly. When I click on the tab tick to close the selected tab. Always the first tab is closed, and not the current clicked tab. What I want is, close the tab that was clicked. Here only the first tab is closed instead of the clicked tab.
动态创建的选项卡与primefaces p:tabView不正确关闭。当我点击选项卡时关闭所选的选项卡。总是第一个选项卡是关闭的,而不是当前单击的选项卡。我想要的是,关闭被点击的标签。这里只关闭第一个选项卡,而不是单击tab。
My JSF:
我的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>
:::::::::::::::::::::::
My Jsf Bean:
我的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;
}
:::::::::::::::::::
My Class NeuTab:
我班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;
}
}
1 个解决方案
#1
0
Try using the TabCloseEvent.
试着用TabCloseEvent。
In your bean:
在你的豆:
import org.primefaces.event.TabCloseEvent;
public void closeme(TabCloseEvent event) {
tabs.remove(event.getTab());
}
On the xhtml:
xhtml:
<p:ajax event="tabClose" listener="#{deneBean.closeme}" update="@form" />
Also see:
还看到:
TabView——Closeable
#1
0
Try using the TabCloseEvent.
试着用TabCloseEvent。
In your bean:
在你的豆:
import org.primefaces.event.TabCloseEvent;
public void closeme(TabCloseEvent event) {
tabs.remove(event.getTab());
}
On the xhtml:
xhtml:
<p:ajax event="tabClose" listener="#{deneBean.closeme}" update="@form" />
Also see:
还看到:
TabView——Closeable