在http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionRadioCheckbox.jsf的Primefaces数据表示例之后,我已经能够构建一个数据表,显示来自我的数据源的正确的标题和行数。但是,没有显示数据;它显示空白单元格。
调试后,我发现问题是由于我的DataModel中的以下代码部分:
@Override
public Resource getRowData(String rowKey) {
List<Resource> resources = (List<Resource>) getWrappedData();
for(Resource resource : resources) {
if(resource.getResourceId().equals(rowKey))
return resource;
}
return null;
}
if(resource.getResourceId().equals(rowKey))
条件的计算结果为false,因此不返回Resource
个对象。
我似乎无法看清我做错了什么。我bean
的相关部分如下所示:
public class NewIncidentWizardBean implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(NewIncidentWizardBean.class.getName());
private static Resource[] tmpResources;
static {
tmpResources = new Resource[12];
tmpResources[0] = new Resource(new Long(1), ..., new Long(2));
tmpResources[1] = new Resource(new Long(2), ..., new Long(4));
tmpResources[2] = new Resource(new Long(3), ..., new Long(10));
tmpResources[3] = new Resource(new Long(4), ..., new Long(10));
tmpResources[4] = new Resource(new Long(5), ..., new Long(10));
tmpResources[5] = new Resource(new Long(6), ..., new Long(10));
tmpResources[6] = new Resource(new Long(7), ..., new Long(10));
tmpResources[7] = new Resource(new Long(8), ..., new Long(10));
tmpResources[8] = new Resource(new Long(9), ..., new Long(10));
tmpResources[9] = new Resource(new Long(10), ..., new Long(10));
tmpResources[10] = new Resource(new Long(11), ..., new Long(7));
tmpResources[11] = new Resource(new Long(12), ..., new Long(90));
}
private List<Resource> resources;
private ResourceDataModel resourcesModel;
private Resource selectedResource;
private Resource[] selectedResources;
public NewIncidentWizardBean() {
resources = new ArrayList<Resource>();
for(int i = 0; i < tmpResources.length; i++)
resources.add(tmpResources[i]);
resourcesModel = new ResourceDataModel(resources);
}
public Resource getSelectedResource() {
return selectedResource;
}
public void setSelectedResource(Resource selectedResource) {
this.selectedResource = selectedResource;
}
public Resource[] getSelectedResources() {
return selectedResources;
}
public void setSelectedResources(Resource[] selectedResources) {
this.selectedResources = selectedResources;
}
public Resource getResource() {
return resource;
}
public void setResource(Resource resource) {
this.resource = resource;
}
public List<Resource> getResources() {
return resources;
}
public void setResources(List<Resource> resources) {
this.resources = resources;
}
public ResourceDataModel getResourcesModel() {
return resourcesModel;
}
}
我认为相关部分是:
<p:dataTable id="resources" var="resource" value="#{newDisasterWizardBean.resourcesModel}" paginator="true" rows="10"
selection="#{newDisasterWizardBean.selectedResources}">
<p:column selectionMode="multiple" style="width:18px" />
<p:column headerText="Resource Name">
#{resource.name}
</p:column>
<p:column headerText="Description">
#{resource.description}
</p:column>
<p:column headerText="Resource Type" >
#{resource.type}
</p:column>
<p:column headerText="Units Required">
#{resource.units}
</p:column>
</p:dataTable>
我无法发现我可能做错的事情。任何帮助将受到高度赞赏。提前谢谢。
答案 0 :(得分:1)
你能留下你正在使用哪个PF版本的笔记吗?
从3.3开始,数据表的延迟加载处理发生了变化。
尝试用3.2然后你可以看看你的代码是否正常
另外,我定义了rowKey标记。我想你应该定义它!
要触发选择/取消选择,您还应该定义这些ajax事件:
<p:dataTable id="myid"
value="#{myvalue}" var="valuevar"
selection="#{value.valueSelected}"
rowKey="#{valuevar.onevalue}">
<p:ajax event="rowSelect"
process="@this"
update="@this" />
<p:ajax event="rowUnselect"
process="@this"
update="@this" />
...................
</p:dataTable>
我目前在3.3.1中使用PrimeFaces问题2993中提到的lazy = true参数。
希望有所帮助。