Jsf 具有多个动态列的嵌套DataTable为每行显示相同的数据
我想显示一些需要使用两个嵌套数据表进行迭代的数据(使用Mojarra 2.2.13和Primefaces 6.0)。内部表具有动态的列数。因为我需要为列迭代的对象是两个不同的业务对象,所以我需要两个独立的Jsf 具有多个动态列的嵌套DataTable为每行显示相同的数据,jsf,primefaces,Jsf,Primefaces,我想显示一些需要使用两个嵌套数据表进行迭代的数据(使用Mojarra 2.2.13和Primefaces 6.0)。内部表具有动态的列数。因为我需要为列迭代的对象是两个不同的业务对象,所以我需要两个独立的标记 BackingBean.java @Named @视域 公共类BackingBean实现了可序列化{ 私有静态最终长serialVersionUID=1L; 私人名单家庭; 私人名单国家; 公共无效生成环境(){ this.families=new ArrayList(); 家族f=新家族
标记
BackingBean.java
@Named
@视域
公共类BackingBean实现了可序列化{
私有静态最终长serialVersionUID=1L;
私人名单家庭;
私人名单国家;
公共无效生成环境(){
this.families=new ArrayList();
家族f=新家族(“贝塔”);
f、 getCars().添加(“梅赛德斯”);
f、 getCars()。添加(“保时捷”);
f、 getCars().添加(“大众”);
f、 getCars().添加(“道奇”);
f、 getPersons()。添加(“他”);
f、 getPersons()。添加(“她”);
增加(f);
f=新家族(“阿尔法”);
f、 getCars().添加(“宝马”);
f、 getPersons()。添加(“他”);
f、 getPersons()。添加(“她”);
增加(f);
}
私人无效生成国家(){
this.countries=new ArrayList();
本条。国家。添加(“德国”);
本条。国家。添加(“英格兰”);
本条。国家。添加(“西班牙”);
}
公共列表getFamilies(){
if(null==族){
生成家庭();
}
返回家庭;
}
国家/地区公共列表(){
如果(空==国家){
生成国家();
}
返回国;
}
公营家庭{
私有字符串名称;
私人名单人员;
私家车名单;
公共族(字符串名称){
this.name=名称;
this.persons=new ArrayList();
this.cars=new ArrayList();
}
公共字符串getName(){
返回名称;
}
公众人士名单{
返回人员;
}
公共列表getCars(){
返回车辆;
}
}
}
index.xthml
数据表错误
#{family.name}
#{person}是否。。。
... 这辆车有保险吗?
... 有#{国家}的保险吗?
我得到的结果是所有内部表(id=persons)看起来都一样(参见图1)。第一个内部表指示列的数量(本例中为8)。外部表的第二行(id=族)应仅显示内部表的5列(仅BMW列)。但仍然显示第一行中的所有列。如果我删除一个p:columns
,一切正常(参见图2)
我查阅了p:dataTable
的文档,似乎没有限制,每个p:dataTable
只允许一个p:columns
。我错过什么了吗
你说得对,我可以重现这个场景。可能是PrimeFaces的错误,或者不支持多个p:columns。作为一种解决方法,您可以使用c:forEach作为国家/地区列表:
<c:forEach items="#{backingBean.countries}" var="country">
<p:column headerText="#{country}">
... have insurance for #{country}
</p:column>
</c:forEach>
... 为#{国家}购买保险
是的,对于这个“简单”的示例,它会起作用。但是,一旦列表是动态的,并且需要从系列
(这是我在应用程序中发现的场景)中获取,它就不会(很遗憾)。是的,这是正确的,请参阅以获取解释。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>DataTable BUG</title>
</h:head>
<body>
<h:form id="form">
<p:dataTable id="families" value="#{backingBean.families}" var="family">
<p:column headerText="Families">
<h3>#{family.name}</h3>
<p:dataTable id="persons" value="#{family.persons}" var="person">
<p:column headerText="Name">
Does #{person} ...
</p:column>
<p:columns value="#{family.cars}" var="car" headerText="#{car}">
... have insurance for the #{car}?
</p:columns>
<p:columns value="#{backingBean.countries}" var="country" headerText="#{country}">
... have insurance for #{country}?
</p:columns>
</p:dataTable>
</p:column>
</p:dataTable>
</h:form>
</body>
</html>
<c:forEach items="#{backingBean.countries}" var="country">
<p:column headerText="#{country}">
... have insurance for #{country}
</p:column>
</c:forEach>