Primefaces数据表行选择在Viewscope中不起作用 [英] Primefaces datatable row selection does not work in viewscope

查看:130
本文介绍了Primefaces数据表行选择在Viewscope中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my application I am using ViewScoped Bean and it does not show selected row when a row is selected in primefaces datatable. But if I changed the Bean to a SessionScoped Bean then it shows the selected row perfectly.

我的代码如下.

 <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就是这样.

and my managedBean CDI is like this.

    @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的情况下帮助我选择行.

and PMData and PMDataModel classes are working normally. Can someone help me to select the row while still using viewscoped bean.

推荐答案

我想我找到了答案.该错误与对话框有关.我在对话框中输入了dynamic = true.现在工作正常.

I think I found the answer. the error is with the dialogbox. I put dynamic=true in dialogbox. Now working perfectly.

这篇关于Primefaces数据表行选择在Viewscope中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆