2012-06-08 83 views
0

遵循Primefaces數據表示例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> 

我不能發現什麼,我可能是做錯了,但。任何援助將不勝感激。提前致謝。

回答

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提到的懶惰= true參數。

希望有所幫助。

+0

我解決了我的問題,通過從處理表數據的commandButton中刪除過程標記! –