how to get which tab is clicked when accordion is loaded intially on a page

你离开我真会死。 提交于 2019-12-12 02:23:42

问题


I have an accordion panel with tabs containing name of students. I select on one of the tab and choose edit. I am calling a tab change listener and getting student object and trying to edit it works fine.

But My problem is when for the first time Accordion loads, even though I select on the tab,and click on edit, I will get not get student object. Its giving me null pointer exception. since Tab change event does not get called for the first time it loads. How do I solve this?

private StudBean formBean;

    public StudBean  getFormBean() {
        if(formBean==null){
            formBean= new StudBean();
        }

        return formBean;
    }

    public void onTabChange(TabChangeEvent event) {
        formBean = (StudBean) event.getData();
    }


public String edit(){


            formBean = testDelegate.getDetails(formBean.getName(),formBean.getId());


        return "/ui/EditStudent?faces-redirect=true";
    }




<p:commandButton process="@this" value="edit"  action="#{testBean.edit}" >

    <p:accordionPanel  value="#{testBean.students}" var="stud">  
                  <p:ajax event="tabChange"  listener="#{testBean.onTabChange}" immediate="true"/>
                  <p:tab title="#{stud.name}">  

来源:https://stackoverflow.com/questions/15245275/how-to-get-which-tab-is-clicked-when-accordion-is-loaded-intially-on-a-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!