jsf对话框不显示primefaces数据表中的选定记录

时间:2013-09-19 05:20:01

标签: jsf primefaces datatable dialog

我想显示一个数据表,一旦选择了一个条目,它的内容应该显示在一个单独的对话框中。 我的代码是这样的。

<h:form id="form">  
        <p:growl id="msgs" showDetail="true" />  
        <p:dataTable id="PMDatas" var="pMData" rowIndexVar="rowIndex" value="#
{managedBean.dataModel}" paginator="true" rows="100"  
                     selection="#{managedBean.selectedRecord}" 
selectionMode="single">  

            <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="#">  
         #{rowIndex+1}
    </p:column>  

    <p:column headerText="Cell Name">  
        <h:outputText value="#{pMData.cellid}" />  
    </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;">  

      <h:outputText value="CellId:" />  
      <h:outputText value="#{managedBean.selectedRecord.cellid}" style="font-
weight:bold"/>  


    </h:panelGrid>  

        </p:dialog>  

</h:form> 

我的pMData类如下所示。

public class PMData implements Serializable{
public PMData(String cell) {

    cellid=cell;

}

private String cellid;

public void setCellid(String cellid){
    this.cellid=cellid;
}



public String getCellid(){

    return cellid;
}
}

和PMDataModel类是这样的。

public class PMDataModel   extends ListDataModel<PMData> implements SelectableDataModel<PMData> ,Serializable{

/**
 * Creates a new instance of PMDataModel
 */
public PMDataModel(){
}

@Override
public Object getRowKey(PMData object) {
    return object.getCellid();
}

@Override
public PMData getRowData(String rowKey) {

    List<PMData> data = (List<PMData>) getWrappedData();  

    for(PMData entry: data) {  
        if(entry.getCellid().equals(rowKey))  
            return entry;  
    }  

    return null;  
}

 public PMDataModel(List<PMData> data) {  
    super(data);  
 }
}

执行此选定条目时,会在Facesmessages中显示,但不会出现在对话框中。

我的mangedbean类ID如下所示。

private PMDataModel dataModel;
private PMData selectedRecord;
public void setSelectedRecord(PMData selectedRecord){
this.selectedRecord=selectedRecord;

}

public PMData getSelectedRecord(){
return  selectedRecord;
}
public managedBean() {
   dataAll= new ArrayList<PMData>();

   this.getFiles(dataAll);
   dataModel = new PMDataModel(dataAll);

}
public ArrayList<PMData> getDataAll(){

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

     System.out.println("inside onRow select  Method");
    FacesMessage msg = new FacesMessage("Row Selected",  ((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;  
} 

2 个答案:

答案 0 :(得分:0)

gosk:我认为这会对你有所帮助。只需替换更新属性的值

即可

<p:ajax event="rowSelect" listener="#{managedBean.onRowSelect}"
update="@form :msgs"

答案 1 :(得分:0)

我在创建JSF托管类时错误地放置了Request范围。将其更改为会话范围后,它开始正常工作。