我正在尝试使用showcase example中显示的方法在单击其中一个列中的命令按钮时显示包含输入文本区域的对话框弹出窗口。在我的情况下,数据表是多个选择< / strong>启用了 datamodel 的实现。只有当数据表具有与展示中显示的相同功能但实现多个选择时(带或不带数据模式实现),才会出现带文本区域的弹出窗口没有任何内容显示在文本区域中,当我检查一行并单击命令按钮时,我得到以下异常。当我直接单击命令按钮时,不会抛出任何异常。
javax.faces.FacesException
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:86)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at com.gaic.datamodel.CarDataModel.getRowData(CarDataModel.java:27)
at com.gaic.datamodel.CarDataModel.getRowData(CarDataModel.java:1)
at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:953)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:71)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:40)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:57)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:796)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:228)
at javax.faces.component.UIForm.processDecodes(UIForm.java:216)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:926)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
... 15 more
我的JSF页面摘录
<h:body>
<h:form id="form">
<p:growl id="msgs" showDetail="true" />
<p:dataTable id="cars" var="car" value="#{tableBean.mediumCarsModel}"
selection="#{tableBean.selectedCars}">
<p:column selectionMode="multiple" style="width:2%" />
<p:column headerText="Model" style="width:24%">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year" style="width:24%">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Manufacturer" style="width:24%">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="Color" style="width:24%">
<h:outputText value="#{car.color}" />
</p:column>
<p:column style="width:4%">
<p:commandButton id="selectButton" update=":form:display"
oncomplete="carDialog.show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{car}"
target="#{tableBean.selectedCar}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
id="carDlg" showEffect="fade" hideEffect="explode" modal="true">
<p:dataList id="display" value="#{tableBean.selectedCar}"
var="selectedWorkSpaceItem"
style="border: 0px solid gray;padding-bottom:1px;">
<p:inputTextarea value="#{selectedWorkSpaceItem.color}">
</p:inputTextarea>
</p:dataList>
</p:dialog>
</h:form>
我的托管bean
public class TableBean implements Serializable {
private final static String[] colors;
private final static String[] manufacturers;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
private List<Car> cars;
private Car selectedCar;
private CarDataModel mediumCarsModel;
private Car[] selectedCars;
public TableBean() {
cars = new ArrayList<Car>();
populateRandomCars(cars, 50);
mediumCarsModel = new CarDataModel(cars);
}
private void populateRandomCars(List<Car> list, int size) {
for (int i = 0 ; i < size ; i++)
list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public List<Car> getCars() {
return cars;
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomManufacturer() {
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel() {
return UUID.randomUUID().toString().substring(0, 8);
}
public CarDataModel getMediumCarsModel() {
if(mediumCarsModel==null) {
System.out.println("yes it is null!!!!!!");
mediumCarsModel = new CarDataModel(cars);
}
return mediumCarsModel;
}
public void setMediumCarsModel(CarDataModel mediumCarsModel) {
this.mediumCarsModel = mediumCarsModel;
}
public Car[] getSelectedCars() {
return selectedCars;
}
public void setSelectedCars(Car[] selectedCars) {
this.selectedCars = selectedCars;
}
}
有什么方法可以显示对话框文本区域中的内容吗?
答案 0 :(得分:0)
您是否使用@annotations标记您的bean?还是faces-config.xml
档案?尝试使用@ManagedBean
和@ViewScoped
为您的bean添加注释。看一看in this J2EE 6 documentation。
@ManagedBean
@ViewScoped
public class TableBean implements Serializable {
private final static String[] colors;
private final static String[] manufacturers;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
private List<Car> cars;
private Car selectedCar;
private CarDataModel mediumCarsModel;
private Car[] selectedCars;
public TableBean() {
cars = new ArrayList<Car>();
populateRandomCars(cars, 50);
mediumCarsModel = new CarDataModel(cars);
}
private void populateRandomCars(List<Car> list, int size) {
for (int i = 0 ; i < size ; i++)
list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public List<Car> getCars() {
return cars;
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomManufacturer() {
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel() {
return UUID.randomUUID().toString().substring(0, 8);
}
public CarDataModel getMediumCarsModel() {
if(mediumCarsModel==null) {
System.out.println("yes it is null!!!!!!");
mediumCarsModel = new CarDataModel(cars);
}
return mediumCarsModel;
}
public void setMediumCarsModel(CarDataModel mediumCarsModel) {
this.mediumCarsModel = mediumCarsModel;
}
public Car[] getSelectedCars() {
return selectedCars;
}
public void setSelectedCars(Car[] selectedCars) {
this.selectedCars = selectedCars;
}
}
答案 1 :(得分:0)
1.您需要在dataTable中添加rowKey。
<p:dataTable id="cars" var="car" rowKey="#{car.model}" value="#{tableBean.mediumCarsModel}"
selection="#{tableBean.selectedCars}">
2.您需要在数据表的标题中单击一个按钮,然后单击该按钮以显示对话框。由于您选择了多行,因此您不需要在每行上使用按钮,如示例所示。
<f:facet name="header">
<p:commandButton value="Click" onclick="PF('carDialog').show();" update=":form:display" />
</f:facet>
3.您希望在对话框TextArea中显示哪些数据?数据表有多列,即模型,年份,制造商,颜色。您可能希望将组件从textArea更改为在对话框中显示列表(例如dataList或datatable)的任何组件。