0

在我的应用程序中,我使用的是 ViewScoped Bean,当在 primefaces 数据表中选择一行时,它不显示选定的行。但是,如果我将 Bean 更改为 SessionScoped Bean,那么它会完美地显示所选行。

我的代码如下所示。

 <h:form id="form">  
 <p:growl id="msgs" showDetail="true" />  
 <p:dataTable  var="pMData" rowIndexVar="rowIndex" value="#       {managedBean.dataModel}" selectionMode="single"  paginator="true" rows="100"   
 widgetVar="pMTable" emptyMessage="No Records Found."      filteredValue="#{managedBean.filteredRecords}" selection="#{managedBean.selectedRecord}"      rowKey="#{pMData.cellid}">  

 <p:ajax event="rowSelect" listener="#{managedBean.onRowSelect}"  
 update=":form:display :form:msgs" oncomplete="moreviewDialog.show()" />  
 <p:ajax event="rowUnselect" listener="#{managedBean.onRowUnselect}"              update=":form:msgs"/>  
 <p:column headerText="Cell Name" filterBy="#{pMData.cellid}"              filterStyle="display:none" >  
 <h:outputText value="#{pMData.modifiedCellID}" />  
    </p:column>   
    </p:dataTable>  


    <p:dialog header="History Data" widgetVar="moreviewDialog" resizable="false" id="moreviewDlg"  
    showEffect="fade" hideEffect="explode" modal="true">  

    <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">  

    <p:lineChart id="category" value="#                {managedBean.createCategoryModel(managedBean.selectedRecord.cellid)}" legendPosition="e"  
 title="NodeB Throughput(kbit/s)" minY="0" maxY="5000" style="height:300px;margin-top:20px"/>  


    </h:panelGrid>  
    </p:dialog>  
    </h:form> 

我的 managedBean CDI 是这样的。

    @Named(value = "managedBean")
    @ViewScoped
    public class ManagedBean implements Serializable {
public void setSelectedRecord(PMData selectedRecord1){
   this.selectedRecord=selectedRecord1;

}

public PMData getSelectedRecord(){

    return  selectedRecord;
}
public void onRowSelect(SelectEvent event) {  


    FacesMessage msg = new FacesMessage("NodeB Selected", String.valueOf(((PMData)     event.getObject()).getCellid()));  

    FacesContext.getCurrentInstance().addMessage(null, msg);  

 }

public void onRowUnselect(UnselectEvent event) {  
FacesMessage msg = new FacesMessage("Row Unselected",((PMData)     event.getObject()).getCellid());  

FacesContext.getCurrentInstance().addMessage(null, msg);  
} 

public PMDataModel getDataModel() {  
    return dataModel;  
} 
public CartesianChartModel createCategoryModel(String key) {  .....}
public List<PMData> getFilteredRecords() {  
    return filteredRecords;  
}  

public void setFilteredRecords(List<PMData> filteredRecords) {  

//        System.out.println("came ");
    this.filteredRecords = filteredRecords;  
}
}

PMData 和 PMDataModel 类工作正常。有人可以在仍然使用 viewscoped bean 的同时帮助我选择行吗?

4

1 回答 1

0

我想我找到了答案。错误在于对话框。我把 dynamic=true 放在对话框中。现在工作完美。

于 2013-09-29T04:16:39.257 回答