문제

The TabCloseEvent is not getting fired if tabs generated from backing bean. TabCloseEvent is working fine with normal xhtml tabs.

Here is my code

   <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui">
        <h:head>
            <title>Test Title</title>
        </h:head>
        <h:body>
            <h:form id="form">
                <p:growl id="growl" showDetail="true" />

                <p:tabView id="tabview"
                           value="#{TestBean.tabList}"
                           var="tab"
                           widgetVar="tabviewV">

                    <p:ajax event="tabClose" listener="#{TestBean.onTabCloseAction}"  update=":form:growl"/>
                    <p:tab id="tab"  title="#{tab}" closable="true" >
                        <h:outputText value="#{tab}"/>
                    </p:tab>
                </p:tabView>

            </h:form>

        </h:body>
    </html>

the managed bean

    @ManagedBean(name = "TestBean")
    @ViewScoped
    public class TestBean {

        private List<String> tabList = new ArrayList<String>();

        public TestBean() {
            tabList.add("Test Tab 1");
            tabList.add("Test Tab 2");
            tabList.add("Test Tab 3");
            tabList.add("Test Tab 4");
        }

        public void onTabCloseAction(TabCloseEvent event) {
            System.out.println("Tab Closed Event : " + event.getTab().getTitle());
            FacesMessage msg = new FacesMessage("Tab Closed", "Closed tab: " + event.getTab().getTitle());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }

        public List<String> getTabList() {
            return tabList;
        }

        public void setTabList(List<String> tabList) {
            this.tabList = tabList;
        }
    }

I'm using Primefaces 5.0. also I tried using process="@this" in side p:ajax but result is same.

도움이 되었습니까?

해결책

I tried the way it was mentioned in the showcase as well as in your code but does not work fully so i tried another approach lets have look

Facelets

  <p:growl id="growl" showDetail="true" />
<p:tabView id="tabView" binding="#{homeBean.tabView}" >

        <p:ajax event="tabClose" listener="#{homeBean.onTabClose}" update=":form:growl"/>

    </p:tabView>

Managed Bean

    private TabView tabView = new TabView();

    Tab tab1 = new Tab();
    tab1.setClosable(true);
    tab1.setTitle("Business Partner");
    Tab tab2 = new Tab();
    tab2.setClosable(true);
    tab2.setTitle("Manage Favorites");
    tabView.getChildren().add(tab1);
    tabView.getChildren().add(tab2);

now it seems to be working. Note : I used Primefaces 5.0

다른 팁

This is a known bug.

It has been fixed in 5.0.2 version.

So you should just update your library to 5.0.2 or 5.0.3

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top