hello
II’m having a problem with vaadin table. When I change row of values displayed returns NullPointerException and I don’t know why. In vaadin book chapter5 Table, there a method setNullSelectionAllowed(false) when this problem happens, but still doesn’t work to me.
I’m trying this.
// Table
Table tabela = new Table();
tabela.setSizeFull();
tabela.addContainerProperty("Aperfeiçoamento", String.class, null);
tabela.addContainerProperty("Entidade", String.class, null);
tabela.addContainerProperty("Início", String.class, null);
tabela.addContainerProperty("Conclusão", String.class, null);
tabela.setNullSelectionAllowed(false);
tabela.setImmediate(true);
tabela.setSelectable(true);
tabela.setColumnReorderingAllowed(false);
tabela.addValueChangeListener(this);
/** listener */
@Override
public void valueChange(ValueChangeEvent event) {
/** preenche os campos do formulario com o id do aperfeicoamento */
if(event.getProperty().getValue() != null){
String id = event.getProperty().getValue().toString();
List<Aperfeicoamento> lista = new AperfeicoamentoDAO().getAperfeicoamentoById(Integer.parseInt(id));
if(!lista.isEmpty()){
try{
for(Aperfeicoamento apf : lista){
aperfeicoamento.setValue(apf.getAperfeicoamento());
entidadeEnsino.setValue(apf.getEntidadeEnsino());
cidade.setValue(apf.getCidade());
comboEstado.setValue(apf.getEstado());
inicio.setValue(new SimpleDateFormat("dd/MM/yyyy").parse(apf.getInicio()));
conclusao.setValue(!apf.getConclusao().isEmpty() ? new SimpleDateFormat("dd/MM/yyyy").parse(apf.getConclusao()) : null);
}
}catch(ParseException e){
e.printStackTrace();
}
}
}
}
/** DAO */
public List<Aperfeicoamento> getAperfeicoamentoById(Integer id){
List<Aperfeicoamento> lista = new ArrayList<Aperfeicoamento>();
try{
PreparedStatement stm = this.con.prepareStatement("SELECT * FROM aperfeicoamento WHERE idAperfeicoamento = ? AND cpf = ?");
stm.setInt(1, id);
stm.setString(2, SessionCurriculum.getCpfInSession());
ResultSet rs = stm.executeQuery();
if(rs.next()){
Aperfeicoamento apf = new Aperfeicoamento();
apf.setIdAperfeicoamento(rs.getInt("idAperfeicoamento"));
apf.setAperfeicoamento(rs.getString("aperfeicoamento"));
apf.setEntidadeEnsino(rs.getString("entidadeensino"));
apf.setCidade(rs.getString("cidade"));
apf.setEstado(rs.getString("estado"));
apf.setInicio(new ControlaDatas().getDataFormatada(rs.getString("inicio")));
apf.setConclusao(rs.getString("conclusao") == null ? null : new ControlaDatas().getDataFormatada(rs.getString("conclusao")));
lista.add(apf);
}
rs.close();
stm.close();
}catch(SQLException e){
new Notification("Erro tentando select em aperfeiçoamento <br/>", e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE, true).show(Page.getCurrent());
}
return lista;
}
// StackTrace
com.vaadin.event.ListenerMethod$MethodException: Invocation of method valueChange in br.ind.ibg.curriculunsibg.views.CursosView failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:167)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1126)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:542)
at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:702)
at com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:521)
at com.vaadin.ui.Table.changeVariables(Table.java:2880)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
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:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NullPointerException
at br.ind.ibg.curriculunsibg.views.CursosView.valueChange(CursosView.java:306)
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 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
... 27 more
Any idea ?