Consider the classes below- Here is the code for the ParentChildRelati.pdf
1. Consider the classes below:
Here is the code for the ParentChildRelation class:
import java.util.Date;
import java.util.Map;
public class ParentChildRelation {
private int rec_id;
private String name;
private Date startDate;
private Date endDate;
private Map<String, Integer> childData;
public int getRec_id() {
return rec_id;
}
public void setRec_id(int rec_id) {
this.rec_id = rec_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getStartDate() {
2. return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Map<String, Integer> getChildData() {
return childData;
}
public void setChildData(Map<String, Integer> childData) {
this.childData = childData;
}
}
Here is the code for the Service class:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
3. import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ParentChildRelationService {
private List<ParentChildRelation> parentChildRelationList;
public void init() {
parentChildRelationList = new ArrayList<>();
// Adding records for Unit01
ParentChildRelation unit01Record1 = new ParentChildRelation();
unit01Record1.setRec_id(1001);
unit01Record1.setName("Unit01");
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
try {
Date startDate = dateFormat.parse("01-01-2023");
Date endDate = dateFormat.parse("31-01-2023");
unit01Record1.setStartDate(startDate);
unit01Record1.setEndDate(endDate);
} catch (Exception e) {
e.printStackTrace();
}
Map<String, Integer> unit01Record1ChildData = new HashMap<>();
unit01Record1ChildData.put("key1", 83);
unit01Record1ChildData.put("key2", 65);
8. <f:facet name="header">End Date</f:facet>
#{parentChildRelation.endDate}
</h:column>
<ui:repeat value="#{parentChildRelation.childData.entrySet().toArray()}" var="entry">
<h:column>
<f:facet name="header">#{entry.key}</f:facet>
#{entry.value}
</h:column>
</ui:repeat>
</h:dataTable>
</h:body>
Give the java main code to call the following classes and display the below data in
datatable list using xhtml, the catch is the child data will be in Map with key pair values and we
need to display in same order as first record for that unit appears,
One point of time one table contains listing of only one unit, and columns for one unit remains
same.
Display the output as below by navigating through two pages from parent object to child object
using xhtml
Parent table begin{tabular}{|l|l|r|} hline 1002 & key1 & 45 hline 1002 & key2 & 98 hline
1002 & key3 & 25 hline 1002 & key4 & 36 hline 1002 & key5 & 95 hline 1002 & key6
& 83 hline 1002 & key7 & 65 hline end{tabular}