我有学生班的名单,学生有自己的课程清单。通过Hibernate Criteria API我按名称选择了学生,加入了课程,所以我有这样的结构:
Student ID=1, Courses.size=2
Student ID=1, Courses.size=2
Student ID=2, Courses.size=1
Student ID=3, Courses.size=2
Student ID=3, Courses.size=2
学生的课程重复次数。这就是我想要做的。但是我在Primefaces数据表中显示它有问题。
<p:dataTable var="student" rowIndexVar="row" selectionMode="single" paginator="true" value="#{studentsMB.students}" lazy="true" rows="30">
<p:column id="tematpl" headerText="Temat pracy dyplomowej">
<h:outputText value="#{student.name}" />
</p:column>
<p:column headerText="Test">
<h:outputText value="#{student.courses[???].name} " />
</p:column>
</p:dataTable>
如何在“???”中包含变量这个地方,所以我可以显示每个课程的名称吗?
答案 0 :(得分:1)
从UI角度使用素数subtable或rowexpansion 更好
对于行扩展,一个简单的结构将是
<p:dataTable var="student" rowIndexVar="row" selectionMode="single" paginator="true" value="#{studentsMB.students}" lazy="true" rows="30">
<p:column style="width:2%">
<p:rowToggler />
</p:column>
<p:column id="tematpl" headerText="Temat pracy dyplomowej">
<h:outputText value="#{student.name}" />
</p:column>
<p:rowExpansion>
<p:datatable value="#{student.courses}" var="course"
<p:column headerText="Course name">
<h:outputText value="#{course.name}" />
</p:column>
</p:datatable>
</p:rowExpansion>
</p:dataTable>