使无线电数据表primefaces适应我的情况jsf2

时间:2012-09-03 11:11:45

标签: jsf-2 datatable primefaces radio-button

我想使用这个收音机数据表: here

但我想触发对话框而不点击查看按钮,

这是我的xhtml页面:

    <?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>TODO supply a title</title>
    </h:head>
    <h:body>
        <h:form id="form">  

            <p:dataTable id="cars" var="car" value="#{newJSFManagedBean.mediumPapiersModel}" paginator="true" rows="10"  
                         selection="#{newJSFManagedBean.selectedPapier}"  >  

                <f:facet name="header">  
                    RadioButton Based Selection  
                </f:facet>  

                <p:ajax event="rowSelect" listener="#{newJSFManagedBean.onRowSelect}"   
                    update=":form:display" oncomplete="carDialog.show()" />  

                <p:column selectionMode="single" style="width:18px" />  

                 <p:ajax event="rowSelect" listener="#{newJSFManagedBean.onRowSelect}"   
                    update=":form:display" oncomplete="carDialog.show()" /> 

                <p:column headerText="libelle">  
                    #{car.libelle}  
                </p:column>  

                <p:column headerText="format">  
                    #{car.format}  
                </p:column>  

                <p:column headerText="stock" >  
                    #{car.stock}  
                </p:column>  


            </p:dataTable>  

            <p:dialog id="dialog" header="Car Detail" widgetVar="carDialog" resizable="false"  
                      showEffect="explode" hideEffect="explode">  

                <h:panelGrid id="display" columns="2" cellpadding="4">  

                     <h:outputText value="id" />  
                     <h:outputText value="#{newJSFManagedBean.selectedPapier.id}" />  

                    <h:outputText value="format" />  
                    <h:outputText value="#{newJSFManagedBean.selectedPapier.format}" />  

                    <h:outputText value="grammage" />  
                    <h:outputText value="#{newJSFManagedBean.selectedPapier.grammage}" />  

                    <h:outputText value="libelle" />  
                    <h:outputText value="#{newJSFManagedBean.selectedPapier.libelle}" />  
                </h:panelGrid>  
            </p:dialog>  

        </h:form>
    </h:body>
</html>

这是我的managedBean:

package controlleurs.admin;

import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import pojos_mappingFiles.Papier;


@ManagedBean
@SessionScoped
public class NewJSFManagedBean {

    metiers.admin.stockHelper sh;
    Papier selectedPapier;  
    List<Papier> papiers;
    papierDataModel mediumPapiersModel;
    /**
     * Creates a new instance of NewJSFManagedBean
     */
    public NewJSFManagedBean() {
        sh = new metiers.admin.stockHelper();
        papiers = new ArrayList<Papier>();
        papiers = sh.getPapiers();
        for(Papier pap : papiers ){
            pap.setChecked(false);
        }
        mediumPapiersModel = new papierDataModel(papiers);
    }

    public Papier getSelectedPapier() {
        System.out.println("j ai selectionz ");
        return selectedPapier;
    }

    public void setSelectedPapier(Papier selectedPapier) {
        System.out.println("je suis selectionné mon numero : "+selectedPapier.getLibelle());
        this.selectedPapier = selectedPapier;
    }

    public papierDataModel getMediumPapiersModel() {
        return mediumPapiersModel;
    }

    public void onRowSelect(SelectEvent event) {  
        System.out.println("je suis dans onRowSelect");  
    } 

}

这是papierDataModel:

package controlleurs.admin;
import java.util.List;
import javax.faces.model.ListDataModel;   
import org.primefaces.model.SelectableDataModel;  
import pojos_mappingFiles.Papier;


public class papierDataModel extends ListDataModel<Papier> implements SelectableDataModel<Papier> {

    public papierDataModel() {  
    }  

    public papierDataModel(List<Papier> data) {  
        super(data);  
    }  

    @Override
    public Object getRowKey(Papier t) {
        return t.getId().toString();

    }

    @Override
    public Papier getRowData(String rowKey) {
        List<Papier> papiers = (List<Papier>) getWrappedData();  

        for(Papier car : papiers) {  
            if(car.getId().toString().equals(rowKey))  
                return car;  
        }  

        return null;  
    }

}

但是当我检查其中一行时没有出现对话框,我不知道原因,你有什么想法,谢谢

0 个答案:

没有答案