我很难在具有 3 层嵌套列表的 JSP 页面上生成 display:table:
我的主要课程是“ExpenditureTotalsByRegions”,其中有一个“ExpenditureTotalsByTypes”列表“ExpenditureTotalsByTypes”有一个“ExpenditureTotalsByProjects”列表
主要问题是:此表中的行数和列数可能会有所不同: 区域数会有所不同;类型的数量可能会有所不同/地区;项目数量不同/类型
JSP 页面获取“ExpenditureTotalsByRegions”列表,应如下所示:
Region 1
----------------------------------------------------------
Types | Project 1 | Project 2
----------------------------------------------------------
type1 | $1,000 | $2,000
type2 | $2,000 | $2,500
Region 2
----------------------------------------------------------
Types | Project 1 | Project 3 |Project 4
----------------------------------------------------------
type3 | $3,000 | $4,000 | $5,000
type4 | $3,500 | $4,500 | $5,500
type5 | $3,550 | $4,550 | $5,550
(在上面的例子中:'Region 1',Region 2'是区域的名称,'type 1','type 2'等是类型的名称,'Project 1','Project2'等是名称的项目和 $ 支出是在项目中花费的实际金额)
主要类:
public class ExpenditureTotalsByRegions {
protected String fRegion = null;
protected List<ExpenditureTotalsByTypes> fTypeExpenditures = new ArrayList<ExpenditureTotalsByTypes>();
public ExpenditureTotalsByRegions(String region,List<ExpenditureTotalsByTypes> typeExpenditures) {
fRegion = region;
fTypeExpenditures = typeExpenditures;
}
public String getRegion() {
return fRegion;
}
public void setRegion(String region) {
fRegion = region;
}
public List<ExpenditureTotalsByTypes> getTypeExpenditures() {
return fTypeExpenditures ;
}
public void setTypeExpenditures( List<ExpenditureTotalsByTypes> typeExpenditures) {
fTypeExpenditures = typeExpenditures;
}
}
现在,“ExpenditureType”类看起来像:
public class ExpenditureTotalsByTypes{
protected String fTypeName;
protected List<ExpenditureTotalsByProjects> fProjectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
public String getTypeName() {
return fTypeName;
}
public void setTypeName(String typeName) {
fTypeName= typeName;
}
public List<ExpenditureTotalsByProjects> getProjectExpenditures() {
return fProjectExpenditures;
}
public void setProjectExpenditures( List<ExpenditureTotalsByProjects> projectExpenditures) {
fProjectExpenditures = projectExpenditures;
}
}
现在“ExpenditureTotalsByProjects:类看起来像:
public class ExpenditureTotalsByProjects {
protected String fProjectName;
protected Double fProjectExpenditure;
public ExpenditureTotalsByProjects( String projectName, Double projectExpenditure) {
fProjectName = projectName;
fProjectExpenditure = projectExpenditure;
}
public String getProjectName() {
return fProjectName;
}
public void setProjectName( String projectName ) {
fProjectName = projectName;
}
public Double getProjectExpenditure() {
return fProjectExpenditure;
}
public void setProjectExpenditure( Double projectExpenditure ) {
fProjectExpenditure = projectExpenditure;
}
}
我的动作课看起来像:
public class ExpendituresTotalsReportByRegionsAction extends ActionBase {
protected List<ExpenditureTotalsByRegions> fTableData = new ArrayList<ExpenditureTotalsByRegions>();
public ExpendituresTotalsReportByRegionsAction(JpaTransactionManager transactionManager) {
super(transactionManager);
}
@Override
public String execute() throws Exception {
if (fYear != 0) {
fTableData = reportDao.getExpenditureTotalsReportByRegions(fYear);
}
return SUCCESS;
}
public List<ExpenditureTotalsByRegions> getTableData() {
return fTableData;
}
}
现在这是我试图在 JSP 页面上构建表格并获得运行时错误的方式:
<body>
<div class="container">
<div class="prepend-1"><br>
<display:table id="reportTable"
name="tableData"
requestURI=""
cellspacing="0px"
export="true"
class="displaytagTable">
<display:setProperty name="decorator.media.html"
value="gov.doi.expenditures.decorator.TotalSpeciesDecorator"/>
<display:setProperty name="decorator.media.rtf"
value="gov.doi.expenditures.decorator.ItextTotalSpeciesDecorator"/>
<display:setProperty name="decorator.media.pdf"
value="gov.doi.expenditures.decorator.ItextTotalSpeciesDecorator"/>
<display:caption class="titleText ">${reportTable.region}</display:caption>
<c:forEach items="${reportTable.typeExpenditures}" var="typeList">
<display:column title="Types" property="${typeList}.typeName"/>
<c:forEach items="${typeList.projectExpenditures}" var="projectList">
<display:column title="${projectList}.projectName" property="${projectList}.projectExpenditure"/>
</c:forEach>
</c:forEach>
</display:table>
</div>
</div>
</body>
测试数据:
List<ExpenditureTotalsByProjects> projectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
List<ExpenditureTotalsByTypes> TypesExpenditures = new ArrayList<ExpenditureTotalsByTypes>();
List<ExpenditureTotalsByRegions> regionExpenditures = new ArrayList<ExpenditureTotalsByRegions>();
//Test data for reg1
projectExpenditures.add(new ExpenditureTotalsByProjects("project1",1000.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project2",2000.00) );
//1st Types with 2 projects in reg1
ExpenditureTotalsByTypes sp1 = new ExpenditureTotalsByTypes();
sp1.setTypes("Types1");
sp1.setProjectExpenditures(projectExpenditures);
TypesExpenditures.add(sp1);
//2nd Types with 2 projects in reg1
projectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
projectExpenditures.add(new ExpenditureTotalsByProjects("project1",1500.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project2",2500.00) );
ExpenditureTotalsByTypes sp2 = new ExpenditureTotalsByTypes();
sp2.setTypes("Types2");
sp2.setProjectExpenditures(projectExpenditures);
TypesExpenditures.add(sp2);
//regionExpenditures.add(new ExpenditureTotalsByRegions("reg1",TypesExpenditures));
tableData.add(new ExpenditureTotalsByRegions("reg1",TypesExpenditures));
//Test data for reg2
TypesExpenditures = new ArrayList<ExpenditureTotalsByTypes>();
projectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
projectExpenditures.add(new ExpenditureTotalsByProjects("project3",3000.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project4",4000.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project5",5000.00) );
sp1 = new ExpenditureTotalsByTypes();
sp1.setTypes("Types3");
sp1.setProjectExpenditures(projectExpenditures);
TypesExpenditures.add(sp1);
projectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
projectExpenditures.add(new ExpenditureTotalsByProjects("project3",3500.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project4",4500.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project5",5500.00) );
sp2 = new ExpenditureTotalsByTypes();
sp2.setTypes("Types4");
sp2.setProjectExpenditures(projectExpenditures);
TypesExpenditures.add(sp2);
projectExpenditures = new ArrayList<ExpenditureTotalsByProjects>();
projectExpenditures.add(new ExpenditureTotalsByProjects("project3",3550.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project4",4550.00) );
projectExpenditures.add(new ExpenditureTotalsByProjects("project5",5550.00) );
ExpenditureTotalsByTypes sp3 = new ExpenditureTotalsByTypes();
sp3.setTypes("Types5");
sp3.setProjectExpenditures(projectExpenditures);
TypesExpenditures.add(sp3);
tableData.add(new ExpenditureTotalsByRegions("reg2",TypesExpenditures));
出现错误:“java.lang.RuntimeException:java.lang.RuntimeException:javax.servlet.jsp.JspException:查找属性时出错”但我还需要使用“forEach”构建表的帮助。请帮忙
如果您需要更多信息,请与我们联系。提前致谢。