Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the below codes : ParentChildRealtion.java import java.util.Date; import java.util.Map; public class ParentChildRelation { private int rec_id; private String name; private Date startDate; private Date

Consider the below codes :

ParentChildRealtion.java

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 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() { 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 getChildData() { return childData; } public void setChildData(Map childData) { this.childData = childData; } }

ParentChildRelationService.java

import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map;

public class ParentChildRelationService { private static List 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 unit01Record1ChildData = new HashMap<>(); unit01Record1ChildData.put("key1", 83); unit01Record1ChildData.put("key2", 65); unit01Record1ChildData.put("key3", 96); unit01Record1ChildData.put("key4", 45); unit01Record1ChildData.put("key5", 25); unit01Record1ChildData.put("key6", 98); unit01Record1ChildData.put("key7", 45); unit01Record1.setChildData(unit01Record1ChildData); parentChildRelationList.add(unit01Record1); ParentChildRelation unit01Record2 = new ParentChildRelation(); unit01Record2.setRec_id(1002); unit01Record2.setName("Unit01"); try { Date startDate = dateFormat.parse("01-02-2023"); Date endDate = dateFormat.parse("28-02-2023"); unit01Record2.setStartDate(startDate); unit01Record2.setEndDate(endDate); } catch (Exception e) { e.printStackTrace(); } Map unit01Record2ChildData = new HashMap<>(); unit01Record2ChildData.put("key1", 45); unit01Record2ChildData.put("key2", 98); unit01Record2ChildData.put("key3", 25); unit01Record2ChildData.put("key4", 36); unit01Record2ChildData.put("key5", 95); unit01Record2ChildData.put("key6", 83); unit01Record2ChildData.put("key7", 65); unit01Record2.setChildData(unit01Record2ChildData); parentChildRelationList.add(unit01Record2); // Adding records for Unit02 ParentChildRelation unit02Record1 = new ParentChildRelation(); unit02Record1.setRec_id(1003); unit02Record1.setName("Unit02"); try { Date startDate = dateFormat.parse("01-01-2023"); Date endDate = dateFormat.parse("31-01-2023"); unit02Record1.setStartDate(startDate); unit02Record1.setEndDate(endDate); } catch (Exception e) { e.printStackTrace(); } Map unit02Record1ChildData = new HashMap<>(); unit02Record1ChildData.put("key1", 100); unit02Record1ChildData.put("key2", 200); unit02Record1ChildData.put("key3", 300); unit02Record1ChildData.put("key4", 400); unit02Record1ChildData.put("key5", 500); unit02Record1ChildData.put("key6", 600); unit02Record1ChildData.put("key7", 700); unit02Record1.setChildData(unit02Record1ChildData); parentChildRelationList.add(unit02Record1); // Adding records for Unit03 ParentChildRelation unit03Record1 = new ParentChildRelation(); unit03Record1.setRec_id(1004); unit03Record1.setName("Unit03"); try { Date startDate = dateFormat.parse("01-02-2023"); Date endDate = dateFormat.parse("28-02-2023"); unit03Record1.setStartDate(startDate); unit03Record1.setEndDate(endDate); } catch (Exception e) { e.printStackTrace(); } Map unit03Record1ChildData = new HashMap<>(); unit03Record1ChildData.put("key1", 10); unit03Record1ChildData.put("key2", 20); unit03Record1ChildData.put("key3", 30); unit03Record1ChildData.put("key4", 40); unit03Record1ChildData.put("key5", 50); unit03Record1ChildData.put("key6", 60); unit03Record1ChildData.put("key7", 70); unit03Record1.setChildData(unit03Record1ChildData); parentChildRelationList.add(unit03Record1); }

public static void main(String[] args) { ParentChildRelationService service = new ParentChildRelationService(); service.init();

List relations = service.getParentChildRelationList(); for (ParentChildRelation relation : relations) { System.out.println(relation); } }

public static List getParentChildRelationList() { return parentChildRelationList; }

public static void setParentChildRelationList(List parentChildRelationList) { ParentChildRelationService.parentChildRelationList = parentChildRelationList; }

}

Question: Give the xhtml code to Represent the values of parent and child data using a data table.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago