0
Gentlemen, I’m having a hard time getting the objs from my customer search screen, and playing it on the sign-up screen for editing it.
My search screen is with a button with a
<p:button outcome="/cliente/CadastroCliente.xhtml" icon="ui-incon-pencil" title="Editar" >
<f:param name="cliente" value="#{cliente.id}"/>
my customer registration page, on which you will receive the wall meter is like this. 'Cause I’m using omnifaces.
<f:metadata>
<o:viewParam name="cliente" value="#{cadastroClienteBean.cliente}"/>
</f:metadata>
My Class of Customers (Repository):
@SuppressWarnings("unchecked")
public List<Cliente> filtrados(ClienteFilter filtro) {
Session session = manager.unwrap(Session.class);
Criteria criteria = session.createCriteria(Cliente.class);
if (StringUtils.isNotBlank(filtro.getCpf())) {
criteria.add(Restrictions.eq("cpf", filtro.getCpf()));
}
if (StringUtils.isNotBlank(filtro.getNome())) {
criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE));
}
return criteria.addOrder(Order.asc("nome")).list();
}
public Cliente porId(Long id) {
return manager.find(Cliente.class, id);
}
}
Customer Class
@FacesConverter(forClass = Cliente.class)
public class ClienteConverter implements Converter{
//@Inject
private Clientes clientes;
public ClienteConverter() {
clientes = CDIServiceLocator.getBean(Clientes.class);
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Cliente retorno = null;
if (value != null) {
Long id = new Long(value);
retorno = clientes.porId(id);
}
return retorno;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value != null) {
//Cliente cliente = (Cliente) value;
//return cliente.getId() == null ? null : cliente.getId().toString();
return ((Cliente) value).getId().toString();
}
return "";
}
}
However, when my page is executed, which I click on the edit button that has to send the values to the registration page, the following error is returned.
mar 01, 2018 9:34:41 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/cliente/CadastroCliente.xhtml]
java.lang.NullPointerException
at com.moto.converter.ClienteConverter.getAsString(ClienteConverter.java:39)
at javax.faces.component.UIViewParameter.getStringValueFromModel(UIViewParameter.java:378)
at javax.faces.component.UIViewParameter.getStringValue(UIViewParameter.java:327)
at javax.faces.component.UIViewParameter.encodeAll(UIViewParameter.java:313)
at javax.faces.component.UIViewRoot.encodeViewParameters(UIViewRoot.java:1655)
at javax.faces.component.UIViewRoot.encodeEnd(UIViewRoot.java:996)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
2018-03-01 09:34:41,578 ERROR [com.moto.util.jsf.JsfExceptionHandler] Erro de sistema: null
java.lang.NullPointerException
at com.moto.converter.ClienteConverter.getAsString(ClienteConverter.java:39)
at javax.faces.component.UIViewParameter.getStringValueFromModel(UIViewParameter.java:378)
at javax.faces.component.UIViewParameter.getStringValue(UIViewParameter.java:327)
at javax.faces.component.UIViewParameter.encodeAll(UIViewParameter.java:313)
at javax.faces.component.UIViewRoot.encodeViewParameters(UIViewRoot.java:1655)
at javax.faces.component.UIViewRoot.encodeEnd(UIViewRoot.java:996)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Please help me, I don’t know where my mistake is. I’m running out of options; att.
Victor, it worked well, it is no longer giving the error nullPointerException, and is sending the wall meter with the Id to be edited to the screen for the registration screen by the URL, however, it is not populating the fields. Can you tell me if you were able to identify any errors in my code that might be causing this ? 'Cause until then, I already had it all set up to work.
– Rodrigo Nantes