I am using Treetable component to display parent and child objects. I can able to display the parent content by using this tutorial.
In my case, I am using two different objects to display the contents in the TreeTable component. Those objects are following.
- University Detail - It is my parent Object. It contains (Id and Name of each university) as well as child colleges.
- College Detail - It is my child Object. It contains (Id and Name) of each college.
UniversityDetail Class
public class UniversityDetail implements Serializable {
/**
* serialVersionUID -
*/
private static final long serialVersionUID = 1L;
/**
* UniversityId -
*/
private Integer UniversityId;
/**
* UniversityName -
*/
private String UniversityName;
/**
* CollegeDetail -
*/
private List<CollegeDetail> CollegeDetail = new ArrayList<CollegeDetail>();
public Integer getUniversityId() {
return UniversityId;
}
public void setUniversityId(Integer UniversityId) {
this.UniversityId = UniversityId;
}
public String getUniversityName() {
return UniversityName;
}
public void setUniversityName(String UniversityName) {
this.UniversityName = UniversityName;
}
public List<CollegeDetail> getCollegeDetail() {
return CollegeDetail;
}
public void setCollegeDetail(
List<CollegeDetail> collegeDetail) {
this.CollegeDetail = collegeDetail;
}
}
College Detail
public class CollegeDetail implements Serializable{
/**
* CollegeId -
*/
private Integer CollegeId;
/**
* CollegeName -
*/
private String CollegeName;
public Integer getCollegeId() {
return CollegeId;
}
public void setCollegeId(Integer CollegeId) {
this.CollegeId = CollegeId;
}
public String getCollegeName() {
return CollegeName;
}
public void setCollegeName(String CollegeName) {
this.CollegeName = CollegeName;
}
}
How to display these detail classes with the treetable component ? I dont know how to iterate the child elements(College Detail)
I have the following xhtml code to display the parent and child. I could render the parent detail. But I am failing to render the child class detail. Any help is much appreciated.
<p:treeTable value="#{ManagedBean.root}" var="object" id="multiSelect"
selection="#{ManagedBean.selectedNodes}" selectionMode="checkbox">
<f:facet name="header">
College Dropdown
</f:facet>
<p:column style="width:100px">
<f:facet name="header">
University Name
</f:facet>
<h:outputText value="#{object.universityName}" />
</p:column>
<p:column style="display:none">
<f:facet name="header">
University ID
</f:facet>
<h:outputText value="#{object.universityId}" />
</p:column>
</p:treeTable>
ManagedBean
RootTree = new CheckboxTreeNode("Root", null);
for(int i =0 ; i<CompanyDetail.size();i++) {
UniversityDetail universityDetail = UniversityDetail.get(i);
List<CollegeDetail> collegeDetail = universityDetail.getCollegeDetail();
TreeNode parent = new CheckboxTreeNode(universityDetail,RootTree);
for(int j=0; j<collegeDetail.size();j++) {
TreeNode child = new CheckboxTreeNode(collegeDetail.get(j).getCollegeName(),collegeDetail.get(j), parent);
}