0

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

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

2 回答 2

0

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

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

于 2013-09-19T05:59:26.653 回答
0

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

于 2013-09-22T06:17:36.407 回答