primefaces Tabclose事件在侦听器中接收到空选项卡

时间:2019-02-24 10:37:34

标签: jsf primefaces jsf-2

我通过单击“新建”选项卡按钮来生成动态选项卡。这是一个奇怪的问题。当我关闭第一个标签时,我生成了3个标签,但是当我关闭第二个标签时,我们收到了空标签。

这是示例代码

Xhtml页面:

<h:form>
    <p:commandButton id="cmdbutton" value="NewTab"
        actionListener="#{bean.buttonListener}" update=":tabView"></p:commandButton>
</h:form>
<p:tabView id="tabView" dynamic="true" cache="false"
    widgetVar="tabViewVar">

    <p:ajax event="tabClose" listener="#{bean.onTabClose}"
        partialSubmit="true" />

    <p:tab title="Godfather Part I">
        <h:form>
            <p:commandButton id="cmdbutton12" value="button" update=":tabView"></p:commandButton>
            <h:panelGrid columns="2" cellpadding="10">
                <h:outputText value="The story begins as Don Vito Corleone..." />
            </h:panelGrid>
        </h:form>
    </p:tab>
    <c:forEach items="#{bean.dynamicTab}" var="tab">
        <p:tab id="#{tab.id}" binding="#{tab}"></p:tab>
    </c:forEach>
</p:tabView>

Bean:

    public class Bean implements Serializable{

    private static final long serialVersionUID = 1L;

    private List<Tab> dynamicTab = new ArrayList<Tab>();


    public List<Tab> getDynamicTab() {
        return dynamicTab;
    }
    public void setDynamicTab(List<Tab> dynamicTab) {
        this.dynamicTab = dynamicTab;
    }
    public Bean() {
        super();
    }


    public void buttonListener(ActionEvent a){
        HtmlForm f=new HtmlForm();
        Tab tempTab = new Tab();
        String id="abc"+UUID.randomUUID().toString();
        tempTab.setId(id);
        tempTab.setTitle(id);
        tempTab.setClosable(true);
        tempTab.getChildren().add(f);
        dynamicTab.add(tempTab);
    }

    public void onTabClose(TabCloseEvent event) {
        Tab tab = event.getTab();
        dynamicTab.remove(tab);

    }
    }

0 个答案:

没有答案