Thursday, June 8, 2017

Super Model

<H3>SuperModel</H3>

package com.test;

import java.util.List;

public class SuperModel {

private String data;
private String dataType;
private String name;
private String id;
private String cssClass;
private int rowSpan = 1;
private int colSpan = 1;

List<SuperModel> childSuperModel;

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

public String getDataType() {
return dataType;
}

public void setDataType(String dataType) {
this.dataType = dataType;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getCssClass() {
return cssClass;
}

public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}

public int getRowSpan() {
return rowSpan;
}

public void setRowSpan(int rowSpan) {
this.rowSpan = rowSpan;
}

public int getColSpan() {
return colSpan;
}

public void setColSpan(int colSpan) {
this.colSpan = colSpan;
}

public List<SuperModel> getChildSuperModel() {
return childSuperModel;
}

public void setChildSuperModel(List<SuperModel> childSuperModel) {
this.childSuperModel = childSuperModel;
}

@Override
public String toString() {
return "SuperModel [data=" + data + ", dataType=" + dataType + ", name=" + name + ", id=" + id + ", cssClass="
+ cssClass + ", rowSpan=" + rowSpan + ", colSpan=" + colSpan + ", childSuperModel=" + childSuperModel
+ "]";
}

}

package com.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SuperModelTestController {
@Autowired
SuperModelService superModelService;
@RequestMapping("getSuperModelView.htm")
public ModelAndView getSuperModelView(){
ModelAndView view = new ModelAndView("superModelView");
SuperModel superModelTable = superModelService.getSuperModelData();
view.addObject("superModelTable", superModelTable);
return view;
}

}


package com.test;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

@Service
public class SuperModelServiceImpl implements SuperModelService {

private List<List<Object>> getData(){
List<List<Object>> data = new ArrayList<List<Object>>();
for (int i = 0; i < 10; i++) {
List<Object> row = new ArrayList<Object>();
for (int j = 0; j < 5; j++) {
Object obj = "Cell-"+i+"-"+j;
row.add(obj);
}
data.add(row);
}
System.out.println(data);
return data;
}

@Override
public SuperModel getSuperModelData() {
List<List<Object>> data = getData();
SuperModel superModelTable = new SuperModel();
List<SuperModel> superModelTableList = null;
if(data != null && !data.isEmpty()){
superModelTableList = new ArrayList<SuperModel>();
SuperModel superModelRow = new SuperModel();
for (List<Object> listObj : data) {
List<SuperModel> superModelRowList = new ArrayList<SuperModel>();
for (Object object : listObj) {
SuperModel superModelCell = new SuperModel();
superModelCell.setData(object+"");
superModelRowList.add(superModelCell);
superModelRow.setChildSuperModel(superModelRowList);
}
superModelTableList.add(superModelRow);
}
superModelTable.setChildSuperModel(superModelTableList);
}

System.out.println(superModelTable);
return superModelTable;
}
}


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table>
<c:forEach items="${superModelTable.childSuperModel}" var="superModelTableList">
<tr>
<c:forEach items="${superModelTableList.childSuperModel}" var="superModelRow">
<td>
<c:out value="${superModelRow.data}"></c:out>
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
</body>
</html>