我正在使用primefaces
作为我的网络应用程序,我的bean存在问题。我有一个包含两个表的页面,每个表都有自己的bean,其中包含表中所选选项的属性,当我从FIRST表中选择一个值并尝试更改它时,服务器崩溃并告知我所选择的SECOND表属性为null。如果我选择第一个表的一行,我不知道为什么使用第二个表的selected属性。
这是我的html页面:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title> BATCH PARAMETRIZATION</title>
</h:head>
<h:body>
<h:form id="form">
<p:panel>
<p:dataTable
id="singleDT"
var="Params"
value="#{tableMB.precios}"
rendered="true"
selectionMode="single"
selection="#{tableMB.selectedParam}"
rowKey="#{Params.id}"
style="margin-top:10">
<f:facet name="header">
Parametrizacion
</f:facet>
<p:column headerText="Valor">
<h:outputText value="$#{Params.valor}" />
</p:column>
<p:column headerText="Porcentaje">
<h:outputText value="#{Params.porcentaje*100}%" />
</p:column>
<f:facet name="footer" >
<div align="left">
<p:commandButton process="singleDT" update=":form:detalleParametro" icon="ui-icon-search"
value="Modificar" oncomplete="PF('modificarParam').show()"
/>
<p:commandButton process="singleDT" update=":form:detalleParametro" icon="ui-icon-search"
value="Agregar" oncomplete="PF('agregarParam').show()"
/>
</div>
</f:facet>
</p:dataTable>
<p:dialog header="Parametro" widgetVar="modificarParam" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="detalleParametro" style="text-align:center;">
<p:panelGrid columns="2" rendered="#{not empty tableMB.selectedParam}" columnClasses="label,value">
<h:outputText value="Id:" />
<h:outputText value="#{tableMB.selectedParam.id}" />
<h:outputText value="Valor" />
<p:inputText value="#{tableMB.selectedParam.valor}" required="true">
</p:inputText>
<h:outputText value="Porcentaje:" />
<p:inputText value="#{tableMB.selectedParam.porcentaje}" required="true" />
</p:panelGrid>
<p:commandButton update=":form:singleDT" value="Aceptar" action="#{tableMB.modificarParametros()}"
oncomplete="PF('modificarParam').hide()" style="margin-top:10"
/>
</p:outputPanel>
</p:dialog>
<p:dialog header="Parametro" widgetVar="agregarParam" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="detalleParametro2" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Valor" />
<p:inputText value="#{tableMB.nuevoParam.valor}" required="true">
</p:inputText>
<h:outputText value="Porcentaje:" />
<p:inputText value="#{tableMB.nuevoParam.porcentaje}" required="true" />
</p:panelGrid>
<p:commandButton update=":form:singleDT" value="Aceptar" action="#{tableMB.agregarParametros()}"
oncomplete="PF('agregarParam').hide()" style="margin-top:10"
/>
</p:outputPanel>
</p:dialog>
</p:panel>
<p:panel>
<p:dataTable
id="premiosDT"
var="Premios"
value="#{tablePremiosMB.premios}"
rendered="true"
selectionMode="single"
selection="#{tablePremiosMB.selectedPremio}"
rowKey="#{Premios.id}"
style="margin-top:10">
<p:column headerText="Premio">
<h:outputText value="#{Premios.premio}" />
</p:column>
<p:column headerText="Porcentaje">
<h:outputText value="#{Premios.porcentaje*100}%" />
</p:column>
<f:facet name="footer" >
<div align="left">
<p:commandButton process="premiosDT" update=":form:detallePremio" icon="ui-icon-search"
value="Modificar" oncomplete="PF('modificarPremio').show()"
/>
<p:commandButton process="premiosDT" update=":form:detallePremio2" icon="ui-icon-search"
value="Agregar" oncomplete="PF('agregarPremio').show()"
/>
</div>
</f:facet>
</p:dataTable>
<p:dialog header="Premio" widgetVar="modificarPremio" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="detallePremio" style="text-align:center;">
<p:panelGrid columns="2" rendered="true" columnClasses="label,value">
<h:outputText value="Id:" />
<h:outputText value="#{tablePremiosMB.selectedPremio.id}" />
<h:outputText value="Descripcion" />
<p:inputText value="#{tablePremiosMB.selectedPremio.premio}" required="true">
</p:inputText>
<h:outputText value="Porcentaje:" />
<p:inputText value="#{tablePremiosMB.selectedPremio.porcentaje}" required="true" />
</p:panelGrid>
<p:commandButton update=":form:premiosDT" value="Aceptar" action="#{tablePremiosMB.modificarPremio()}"
oncomplete="PF('modificarPremio').hide()" style="margin-top:10"
/>
</p:outputPanel>
</p:dialog>
<p:dialog header="Premio" widgetVar="agregarPremio" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="detallePremio2" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Descripcion" />
<p:inputText value="#{tablePremiosMB.nuevoPremio.premio}" required="true">
</p:inputText>
<h:outputText value="Porcentaje:" />
<p:inputText value="#{tablePremiosMB.nuevoPremio.porcentaje}" required="true" />
</p:panelGrid>
<p:commandButton update=":form:premiosDT" value="Aceptar" action="#{tablePremiosMB.agregarPremio()}"
oncomplete="PF('agregarPremio').hide()" style="margin-top:10"
/>
</p:outputPanel>
</p:dialog>
</p:panel>
</h:form>
</h:body>
</html>
这是第一个表的bean:
package ar.com.nortid.mb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean(name="tableMB")
@ViewScoped
public class TableMB implements Serializable {
/**
*
*/
private List<Params> precios = new ArrayList<Params>();
private Params selectedParam;
private Params nuevoParam = new Params();
private String expirationDate;
public TableMB() {
precios.add(new Params(new Long(1), 2.0, 0.3));
precios.add(new Params(new Long(2), 5.0, 0.2));
precios.add(new Params(new Long(3), 10.0, 0.1));
}
public List<Params> getPrecios() {
return precios;
}
public void setPrecios(List<Params> precios) {
this.precios = precios;
}
public Params getSelectedParam() {
return selectedParam;
}
public void setSelectedParam(Params selectedParam) {
this.selectedParam = selectedParam;
}
public Params getNuevoParam() {
return nuevoParam;
}
public void setNuevoParam(Params nuevoParam) {
this.nuevoParam = nuevoParam;
}
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public void modificarParametros(){
int index = -1;
for(int i=0; i<precios.size(); i++)
if(precios.get(i).getId() == selectedParam.getId())
index = i;
if(index >= 0){
precios.remove(index);
precios.add(selectedParam);
}
}
public void agregarParametros(){
nuevoParam.setId(new Long(precios.size()));
precios.add(nuevoParam);
nuevoParam = null;
nuevoParam = new Params();
}
}
package ar.com.nortid.mb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean(name="tablePremiosMB")
@ViewScoped
public class TablePremiosMB implements Serializable {
/**
*
*/
private List<Premios> premios = new ArrayList<Premios>();
private Premios selectedPremio;
private Premios nuevoPremio = new Premios();
public TablePremiosMB() {
premios.add(new Premios(new Long(1), "Departamento", 0.001));
premios.add(new Premios(new Long(2), "Auto", 0.005));
premios.add(new Premios(new Long(3), "$10000", 0.01));
premios.add(new Premios(new Long(4), "$100", 0.2));
}
public List<Premios> getPremios() {
return premios;
}
public void setPremios(List<Premios> premios) {
this.premios = premios;
}
public Premios getSelectedPremio() {
return selectedPremio;
}
public void setSelectedPremio(Premios selectedPremio) {
this.selectedPremio = selectedPremio;
}
public Premios getNuevoPremio() {
return nuevoPremio;
}
public void setNuevoPremio(Premios nuevoPremio) {
this.nuevoPremio = nuevoPremio;
}
public void modificarPremio(){
int index = -1;
for(int i=0; i<premios.size(); i++)
if(premios.get(i).getId() == selectedPremio.getId())
index = i;
if(index >= 0){
premios.remove(index);
premios.add(selectedPremio);
}
}
public void agregarPremio(){
nuevoPremio.setId(new Long(premios.size()));
premios.add(nuevoPremio);
nuevoPremio = null;
nuevoPremio = new Premios();
}
}
这是我尝试更改第一个表的值时显示的错误:
ADVERTENCIA: /page/BatchParametrization.xhtml @167,83 value="#{tablePremiosMB.selectedPremio.premio}": Objetivo inalcanzable, 'selectedPremio' devolvió nulo
javax.el.PropertyNotFoundException: /page/BatchParametrization.xhtml @167,83 value="#{tablePremiosMB.selectedPremio.premio}": Objetivo inalcanzable, 'selectedPremio' devolvió nulo
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:132)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:171)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.dialog.Dialog.processValidators(Dialog.java:387)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:287)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
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:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
如您所见,selectedPremio返回null但selectedPremio是第二个表的属性,我尝试更改第一个表的一行。我不知道该怎么办。你能给我的任何帮助都会很棒。