0

I am using Wildfly 9.0.1 with PF 5.2 and JSF 2.2. I need to populate a datatable with subtable which displays headers and rows specific to each tab I am iterating. The following "model tree" is wanted to be displayed:

--> Tabs (moduleName)

--> --> Headers

--> --> --> Rows

xhtml:

<p:tabView id ="tabView1" value="#{moduleBean.modules}" var="tabItem">
   <p:tab title="#{tabItem.moduleName}" >
     <p:dataTable  id="mainTable" value="#{subTableView.getAllHeaders(tabItem.moduleName)}" var="head" >
        <p:subTable id="subTable1" value="#{head.rows}" var="row">

I should be using @PostConstruct with the init() initialization method for such expensive operation but JSF does not allow to use init() without void. So I am calling a "lazy method" getAllHeaders(String) but it does not change the String during tab iteration through tabItem.moduleName.

Any method in Tab is iterating properly through Headers and Rows to generate a List of Maps for instance.

Strangely while I need this method to be called the same amount of time that tabs are generated, this method is called only ONCE or TWICE instead of three times for example.

However If I go without the if statment (not lazy) in the Bean of getAllHeaders(String) method I have the correct tree display with Tabs versus Headers and Rows but any method in Tab is NOT iterating through Headers and Rows to generate a List of Maps for instance.

Bean:

@PostConstruct
public void init() {    
    this.modules = publicService.getAllModules();   
}

// Lazy method
public List<Header> getAllHeaders(String module) { 

    if (this.headers == null) {
        this.headers = publicService.getAllHeaders(module);
    }

    return this.headers;    
}


public List<Header> getHeaders() {
    return headers;
}  

Service:

public List<Header> getAllHeaders(String module) {

        List<Module> modules = entityManager.createQuery("select m from Module m",Module.class).getResultList();    

        List<Header> headers = new ArrayList<Header>();  

        for (Module m : modules){   

            if (m.getModuleName().equals(module)){

                    for(Header h : m.getHeaders())
                    {

                       headers.add(h);

                       for(Row q : h.getRows())
                       {

                       } 
                    }
                }
            }

        return headers;
    }

As a reference I used the following Why JSF calls getters multiple times.

Thank you for you time.

Community
  • 1
  • 1
LEK
  • 83
  • 2
  • 11

1 Answers1

0

The solution is precisely what Ali Saleh mentioned on the following: Primefaces tabview tabChange event fired after displaying tab

The solution is the positioning of the <h:form> tag to surround the datatable.

Community
  • 1
  • 1
LEK
  • 83
  • 2
  • 11