我想使用这个无线电数据表: 这里
但我想在不点击查看按钮的情况下触发对话框,
这是我的 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;
}
}
但是当我检查其中一行时对话框没有出现,我不知道原因,你有什么想法,谢谢