【发布时间】:2015-09-14 12:30:07
【问题描述】:
我有一个网格,用户可以在其中看到他的记录,当他单击记录时,它会链接到另一个页面,以便他可以编辑或删除它。
该页面中的记录正确显示,并且它有一个按钮来更新记录,如果发生任何更改并让用户回到网格。
我正在使用带有 Primefaces 的 Java 1.8,在 Netbeans 8.0.2 和 wildfy 8.2 上使用,我的操作系统是 UBUNTU。
当我尝试更改某些内容时,页面什么也不做,我在 wildfly 日志中有此记录
15:11:16,369 错误 [org.jboss.as.ejb3](默认任务 19) javax.ejb.EJBTransactionRolledbackException:找不到查询的实体 15:11:16,371 错误 [org.jboss.as.ejb3.invocation](默认任务 19) JBAS014134:方法的组件 GastoDAOImpl 上的 EJB 调用失败 公共抽象dominio.Gasto persistencia.GastoDAO.getGastoporID(int): javax.ejb.EJBTransactionRolledbackException: 找不到查询的实体
原因:javax.persistence.NoResultException:找不到实体 查询
15:11:16,405 错误 [org.jboss.as.ejb3.invocation](默认任务 19) JBAS014134:组件 GastoControladorImpl 上的 EJB 调用失败 对于方法公共抽象dominio.Gasto controladores.GastoControlador.obtenerGastoporID(int): javax.ejb.EJBTransactionRolledbackException:未找到查询的实体
15:11:16,439 严重 [javax.enterprise.resource.webcontainer.jsf.context](默认任务 19) javax.faces.component.UpdateModelException:javax.el.ELException: /editargastos.xhtml @10,64 value="#{gastoBean.idGasto}": javax.ejb.EJBTransactionRolledbackException: 找不到查询的实体
奇怪的是,如果我在调试模式下运行程序,完全没有问题,系统按预期工作(数据被正确修改,用户回到主网格。
我的代码:
1) 这是显示要修改的项目记录的页面 它在调试模式或正常模式下显示正确的记录
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<f:metadata>
<f:viewParam name="id_gasto" value="#{gastoBean.idGasto}"/>
</f:metadata>
<title>Gaston editar un gasto</title>
</h:head>
<h:body>
<div id="header">
<ui:insert name="header">
<ui:include src="defaultHeader.xhtml" />
</ui:insert>
</div>
<h2>Editar un gasto Propietario: #{loginBean.usuario.apellido}</h2>
<h3>Familia: #{loginBean.usuario.familia.nombre}</h3>
<h:form>
<h:messages></h:messages>
<p:panelGrid columns="2">
<h:outputText value=" Fecha de pago" />
<p:calendar value="#{gastoBean.gasto.fecha_registro}" required="true"/>
<h:outputText value=" Moneda" />
<h:selectOneMenu id="moneda" value="#{gastoBean.gasto.moneda}" >
<f:selectItems value="#{gastoBean.monedas}"></f:selectItems>
</h:selectOneMenu>
<h:outputText value="Monto" />
<h:inputText value="#{gastoBean.gasto.monto}" required="true"/>
<h:outputText value=" Descripcion" />
<h:inputText value="#{gastoBean.gasto.descripcion}" required="true"/>
<h:outputText value=" Clasificacion" />
<h:inputText value="#{gastoBean.gasto.clasificacion}" required="true"/>
</p:panelGrid>
<br></br>
<p:commandButton action="#{gastoBean.modificarGasto()}" value="Modificar gasto" />
<p:commandButton action="#{gastoBean.eliminarGasto(id_gasto)}" value="Eliminar gasto" />
<br></br>
<h:outputText value="#{gastoBean.mensaje}" />
<br></br><br></br>
<hr></hr>
<small>Todos los campos son obligatorios</small>
</h:form>
</h:body>
</html>
2) Backing bean:这是上一页中修改项调用的 bean,当系统在调试模式下运行时,我可以看到每一行都按预期工作,完成后数据库更新,用户发送到网格。
但是...如果我在没有调试选项的情况下运行程序,它根本不起作用,也不会修改数据库,也不会显示用户重定向,也不会显示异常。
public void modificarGasto() {
try {
controlador.modificarGasto(gasto);
Familia f = this.autenticado.getUsuario().getFamilia();
this.listaGastos = controlador.obtenerGastosFamiliaporID(f.getId_familia());
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect("listadog.xhtml");
} catch (Exception e) {
this.mensaje = "ERROR: No se pudo guardar el registro";
}
}
更新:我刚刚修改了按钮附加的方法只是为了给出一条消息,并且在“正常模式”下都不起作用我开始认为这实际上是 Primefaces 中的一个错误:(
【问题讨论】:
-
您的标题错误绝不是由 PrimeFaces 引起的。如果查询中的某些内容的值无效,则可以,但请更改您的标题
标签: jsf jsf-2 viewparams