Reputation: 609
Following the Primefaces datatable example at http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionRadioCheckbox.jsf, I've been able to construct a datatable that displays the correct headers and number of rows from my data source. However, no data is displayed; it displays blank cells.
After debugging, I've discovered the problem is because of the following section of code in my 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;
}
The if(resource.getResourceId().equals(rowKey))
condition evaluates to false, and hence no Resource
object is returned.
I can't seem to see what I'm doing wrong. The relevant sections from my bean
is shown below:
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;
}
}
And the relevant section from my view is:
<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>
I'm not able to discover what I may be doing wrong, yet. Any assistance will be highly appreciated. Thanks in advance.
Upvotes: 0
Views: 3174
Reputation: 21
Could you leave a note which PF version you're using?
Since 3.3 there is a change in lazy loading handling of the data table.
Give it a try with 3.2 then you can see whether you're code works fine.
Additionally I have the rowKey tag defined. I guess you should define it!
For triggering select/unselect you should also define these ajax events:
<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>
I'm currently stick as well in 3.3.1 with the lazy=true parameter mentioned in PrimeFaces issue 2993.
Hope that helps.
Upvotes: 1