如何在最后一个标签附近添加添加新标签的按钮?

有没有人知道如何添加一个按钮来添加位于最后创建的选项卡附近的新选项卡? 如果不清楚我的情况,只需查看浏览器中的选项卡和添加新选项卡的按钮;-)这正是我想要管理的内容。

我正在使用MyFaces + PrimeFaces。

您可以使用显示基于某些bean集合的动态tabset。 您可以将“添加”选项卡显示为选项卡集的最后一个选项卡。 如有必要,您甚至可以采用不同的方式。 您可以使用来挂钩制表符更改侦听器,您可以在其中检查是否已打开“添加”选项卡,然后添加新选项卡。

例如

     

#{tab.content}

 @ManagedBean @ViewScoped public class Bean implements Serializable { private List tabs; @PostConstruct public void init() { // Just a stub. Do your thing to populate tabs. // Make sure that the last tab is the "Add" tab. tabs = new ArrayList(); tabs.add(new Tab("tab1", "content1")); tabs.add(new Tab("tab2", "content2")); tabs.add(new Tab("Add...", null)); } public void changeTab(TabChangeEvent event) { int currentTabIndex = ((TabView) event.getComponent()).getActiveIndex(); int lastTabIndex = tabs.size() - 1; // The "Add" tab. if (currentTabIndex == lastTabIndex) { tabs.add(lastTabIndex, new Tab("tab" + tabs.size(), "content" + tabs.size())); // Just a stub. Do your thing to add a new tab. RequestContext requestContext = RequestContext.getCurrentInstance(); requestContext.update("form:tabs"); // Update the p:tabView to show new tab. requestContext.addCallbackParam("newTabIndex", lastTabIndex); // Triggers the oncomplete. } } public List getTabs() { return tabs; } } 

Tab类在这个例子中只是一个带有属性titlecontent的普通javabean。 oncomplete是必要的,因为在添加新选项卡之后选项卡内容会消失(毕竟它看起来很像PF错误;顺便说一句,我使用的是3.3)。