0

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.

my code is like below.

 <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> 

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;  
}
}

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

gsk
  • 95
  • 4
  • 9
  • waht if you change @Named to managedBean, component... – Darka Sep 28 '13 at 18:43
  • @Darka I changed CDI annoatation to JSF as you suggested and used import javax.faces.bean.ViewScoped; instead of import javax.faces.view.ViewScoped; But then even the datatable does not load. Results is a null poiter exception. – gsk Sep 29 '13 at 01:09
  • Do I have to do anything with web.xml file. Because I didn't do any modification to this file since it was generated. – gsk Sep 29 '13 at 01:33
  • I changed web.xml like below, still same result. javax.faces.PARTIAL_STATE_SAVING false – gsk Sep 29 '13 at 01:58
  • I changed setSelectedRecord method as below.public void setSelectedRecord(PMData selectedRecord1){ this.selectedRecord=selectedRecord1; System.out.println("selected record "+selectedRecord.getCellid()); } and when a row is selected for the first time, system.out.print() gives the selected row correctly. but after that nothing is displayed for any selection. – gsk Sep 29 '13 at 03:06
  • also I changed getSelected record like below. public PMData getSelectedRecord(){ // System.out.println("came "); if(selectedRecord != null){ System.out.println("selected record ddddd"+selectedRecord.getCellid()); } return selectedRecord; } This shows selected row correctly for the first time selection. after that nothing is displayed. @BalusC can someone help? – gsk Sep 29 '13 at 03:10
  • In my program I display selected row in a dialog box chartesian chart. In sessionScoped bean I noticed that even though this displays correctly, I have to refresh the page once before using for the first time. In viewscoped even I refresh the page dialog box does not appear. – gsk Sep 29 '13 at 03:27
  • I think I found the answer. the error is with the dialogbox. I put dynamic=true in dialogbox. Now working perfectly. – gsk Sep 29 '13 at 03:47

1 Answers1

0

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

gsk
  • 95
  • 4
  • 9