I use the same registration form to update a datatable record. when clicking update it sends to the inputText the name to be updated so far so well, the problem is when the name is changed and the button is clicked. the inputText returns to the previous name and the change does not occur.
I noticed that the exception is thrown when the edit link is clicked! and the data goes to the inputText to be edited. When the name is changed and clicked on the save the name back to original and save nothing button there changes the name again and click save there the name is changed! or you have to do more than once to change a given.
I gave a System.out.println (params.get ("id") + "" + params.containsValue ("id")); before the line raising the exception and returned null, false.
Then <f:param
is not sending the id value to the MangedBean.
It's as if the "id" that comes from the view through the param attribute was always sending null!
How can I resolve this?
Page
<h:column>
<f:facet name="header">
<h:outputText value="Editar" />
</f:facet>
<f:ajax event="click" render="@all"
listener="#{localidadeBean.preparaAlteracao}">
<h:commandLink>
<f:param name="id" value="#{localidade.codLocalidade}" />
<h:graphicImage title="editar" library="imagens" name="editar.png"
style="float:right;" />
</h:commandLink>
</f:ajax>
</h:column>
ManagedBean
public void preparaAlteracao() {
Map<String, String> params = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap();
Integer id = Integer.parseInt(params.get("id"));// Linha que levanta a Exceção
facade = new Facade(this.getManager());
try {
this.localidade = facade.procuraLocalidade(id);
} catch (RepositorioException e) {
BaseBean.addErrorMessage("localidade", e.getMessage());
throw new ValidatorException(new FacesMessage("localidade", e.getMessage()));
}
}
Stacktrace
Out 17, 2014 5:56:12 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
Advertência: /lista-de-localidades.xhtml @34,53 listener="# {localidadeBean.preparaAlteracao}": java.lang.NumberFormatException: null
javax.el.ELException: /lista-de-localidades.xhtml @34,53 listener="#{localidadeBean.preparaAlteracao}": java.lang.NumberFormatException: null
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:447)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UIData.broadcast(UIData.java:1092)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:795)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1260)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at br.com.sescpe.scontratos.controle.filtro.JPAFilter.doFilter(JPAFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at br.com.sescpe.scontratos.controle.filtro.ControleAcesso.doFilter(ControleAcesso.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.<init>(Integer.java:677)
at br.com.sescpe.scontratos.controle.managedbean.localidade.LocalidadeBean.preparaAlteracao(LocalidadeBean.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 36 more