按照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))
条件评估为假,因此不返回任何对象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>
我还无法发现我可能做错了什么。任何帮助将不胜感激。提前致谢。