package com.vaadin.ui.view;
public class AddConsumerView extends FormLayout{
private ConsumerUI consumerUI;
@Autowired
private ConsumerServiceInterface consumerServiceInterface;
//horizontal layout for the id's
private HorizontalLayout consumerIDLayout = new HorizontalLayout();
private TextField consumer_id = new TextField("Consumer Id");
private TextField household_id = new TextField("Household Id");
private TextField legal_hold = new TextField("Legal Hold");
private TextField deceased_fg = new TextField("Deceased");
private DateTimeField deceased_dt = new DateTimeField("Deceased DateTime");
//Horizontal layout for the INS
private HorizontalLayout consumerINSLayout = new HorizontalLayout();
private TextField ins_pqid = new TextField("Ins PQID");
private TextField ins_rid = new TextField("Ins RID");
private TextField ins_efid = new TextField("Ins EFID");
private DateTimeField ins_tmstmp = new DateTimeField("Ins Date time");
// Horizontal layout for the UPD
private HorizontalLayout consumerUPDLayout = new HorizontalLayout();
private TextField upd_pqid = new TextField("Upd PQID");
private TextField upd_rid= new TextField("Upd RID");
private TextField upd_efid = new TextField("Upd EFID");
private DateTimeField upd_tmstmp = new DateTimeField("Upd Date time");
private Consumer consumerData = new Consumer();
//Buttons
private Button saveConsumerButton = new Button("save");
//binding the data to the field
private Binder<Consumer> consumerBinder = new Binder<>(Consumer.class);
public AddConsumerView(ConsumerUI consumerUI) {
this.consumerUI = consumerUI;
consumerIDLayout.addComponents(consumer_id, household_id, legal_hold, deceased_dt,deceased_fg);
consumerINSLayout.addComponents(ins_pqid, ins_rid, ins_efid, ins_tmstmp);
consumerUPDLayout.addComponents(upd_pqid,upd_rid, upd_efid, upd_tmstmp);
VerticalLayout vertical = new VerticalLayout();
vertical.addComponents(consumerIDLayout, consumerINSLayout,
consumerUPDLayout,saveConsumerButton);
//addComponent(vertical);
bindFields();
consumerBinder.setBean(new Consumer());
saveConsumerButton.setStyleName("primary");
saveConsumerButton.addClickListener(e->saveConsumer());
addComponents(vertical);
}
public void saveConsumer() {
//consumerBinder.bindInstanceFields(this);
System.out.println(consumerBinder.getBean().toString());
consumerServiceInterface.addConsumer(consumerBinder.getBean());
}
public void bindFields() {
consumerBinder.forField(consumer_id)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getConsumer_id,Consumer::setConsumer_id);
consumerBinder.forField(legal_hold)
.bind(Consumer::getLegal_hold, Consumer::setLegal_hold);
consumerBinder.forField(deceased_fg)
.bind(Consumer::getDeceased_fg, Consumer::setDeceased_fg);
consumerBinder.forField(household_id)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getHousehold_id,Consumer::setHousehold_id);
consumerBinder.forField(ins_efid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getIns_efid,Consumer::setIns_efid);
consumerBinder.forField(ins_pqid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getIns_pqid,Consumer::setIns_pqid);
consumerBinder.forField(ins_rid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getIns_rid,Consumer::setIns_rid);
consumerBinder.forField(upd_efid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getUpd_efid,Consumer::setUpd_efid);
consumerBinder.forField(upd_pqid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getUpd_pqid,Consumer::setUpd_pqid);
consumerBinder.forField(upd_rid)
.withConverter(new StringToLongConverter("Must be a number"))
.bind(Consumer::getUpd_rid,Consumer::setUpd_rid);
consumerBinder.forField(upd_tmstmp)
.withConverter(new StringTimestampConvertor())
.bind(Consumer::getUpd_tmstmp, Consumer::setUpd_tmstmp);
consumerBinder.forField(ins_tmstmp)
.withConverter(new StringTimestampConvertor())
.bind(Consumer::getIns_tmstmp, Consumer::setIns_tmstmp);
consumerBinder.forField(deceased_dt)
.withConverter(new StringTimestampConvertor())
.bind(Consumer::getDeceased_dt, Consumer::setDeceased_dt);
consumerBinder.forField(upd_tmstmp)
.withConverter(new StringTimestampConvertor())
.bind(Consumer::getUpd_tmstmp, Consumer::setUpd_tmstmp);
}
}
StringTimestampConvertor
Класс
package com.vaadin.convertor;
@SuppressWarnings("serial")
public class StringTimestampConvertor implements Converter<LocalDateTime, Timestamp> {
@SuppressWarnings("unchecked")
public Result<Timestamp> convertToModel(LocalDateTime value, ValueContext context) {
System.out.println("check"+value);
Result<Timestamp> rs = Result.ok(Timestamp.valueOf(value));
return rs;
}
@Override
public LocalDateTime convertToPresentation(Timestamp value, ValueContext context) {
// TODO Auto-generated method stub
return null;
}
}
Sysout работает, но функция saveConsumer
выдает нулевую ошибку, а также stringtimestampconvertor запускается много раз.
java .lang.NullPointerException: пусто в com.vaadin.ui.view.AddConsumerView.saveConsumer (AddConsumerView. java: 82) ~ [classes /: na] в com.vaadin.ui.view.AddConsumerView. лямбда $ 0 (AddConsumerView. java: 71) ~ [classes /: na] в com.vaadin.ui.view.AddConsumerView $$ Lambda $ 1501 / 954546734.buttonClick (неизвестный источник) ~ [na: na] в sun.reflect .GeneratedMethodAccessor433.invoke (неизвестный источник) ~ [na: na] at sun.reflect.DelegatingMethodAccessorImpl.invoke (неизвестный источник) ~ [na: 1.8.0_45] at java .lang.reflect.Method.invoke (неизвестный источник) ~ [na: 1.8.0_45] на com.vaadin.event.ListenerMethod.receiveEvent (ListenerMethod. java: 510) ~ [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.event. EventRouter.fireEvent (EventRouter. java: 211) ~ [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.event.EventRouter.fireEvent (EventRouter. * 1 026 *: 174) ~ [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.server.AbstractClientConnector.fireEvent (AbstractClientConnector. java: 1029) ~ [vaadin-server-8.0.0. jar: 8.0.0] на com.vaadin.ui.Button.fireClick (кнопка. java: 370) ~ [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.ui.Button $ 1 .click (кнопка. java: 57) ~ [vaadin-server-8.0.0.jar: 8.0.0] в sun.reflect.GeneratedMethodAccessor432.invoke (неизвестный источник) ~ [na: na] в sun.reflect. DelegatingMethodAccessorImpl.invoke (Неизвестный источник) ~ [na: 1.8.0_45] в java .lang.reflect.Method.invoke (Неизвестный источник) ~ [na: 1.8.0_45] в com.vaadin.server.ServerRpcManager.applyInvocation ( ServerRpcManager. java: 155) ~ [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.server.ServerRpcManager.applyInvocation (ServerRpcManager. java: 116) ~ [vaadin-server-8.0 .0.jar: 8.0.0] на com.vaadin.server.communication.ServerRpcHandler.handleInvocation (ServerRpcHandler. java: 443) [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin. server.communication.ServerRpcHandler.handleInvocations (ServerR pcHandler. java: 415) [vaadin-server-8.0.0.jar: 8.0.0] по адресу com.vaadin.server.communication.ServerRpcHandler.handleRp c (ServerRpcHandler. java: 274) [vaadin- server-8.0.0.jar: 8.0.0] на com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest (UidlRequestHandler. java: 90) [vaadin-server-8.0.0.jar: 8.0.0] на com .vaadin. ) [vaadin-server-8.0.0.jar: 8.0.0] на com.vaadin.server.VaadinServlet.service (VaadinServlet. java: 380) [vaadin-server-8.0.0.jar: 8.0.0] в javax.servlet.http.HttpServlet.service (HttpServlet. java: 742) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org. apache .catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. java: 231) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .tomcat.websocket.server.WsFilter.doFilter (WsFilter. java: 52) [tomcat-embed-websocket -8.5.29.jar: 8.5.29] в орг. apache .catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. java: 193) [tomcat-embed-core-8.5.29.jar: 8.5.29 ] в org. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org.springframework.web.filter. RequestContextFilter.doFilterInternal (RequestContextFilter. java: 99) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] в org.springframework.web.filter.OncePerRequestFilter.doFilter * OncePerRequestFilter * OncePerRequestFilter * 107) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] в org. apache .catalina.core.ApplicationFilterChain. internalDoFilter (ApplicationFilterChain. java: 193) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core-8.5.29.jar: 8.5.29] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal (HttpPutFormContentFilter. java: 109) [spring-web-5.0.5.RELEASE.jar : 5.0.5.RELEASE] в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter. java: 107) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] в орг. apache .catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. java: 193) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.core.ApplicationFilterChain. doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal (HiddenHttpMethodFilter. java: 81): -web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] на org.springframework.web.filter.OncePerRequestFi lter.doFilter (OncePerRequestFilter. java: 107) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] at org. apache .catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. * 1067) *: 193) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core -8.5.29.jar: 8.5.29] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (CharacterEncodingFilter. java: 200) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE ] at org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter. java: 107) [spring-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE] в org. apache .catalina. core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. java: 193) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.core.StandardWrapperValve.invoke (Standa rdWrapperValve. java: 198) [tomcat-embed-core-8.5.29.jar: 8.5.29] в org. apache .catalina.core.StandardContextValve.invoke (StandardContextValve. java: 96) [tomcat -embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase. java: 496) [tomcat-embed-core-8.5.29.jar : 8.5.29] в орг. apache .catalina.core.StandardHostValve.invoke (StandardHostValve. java: 140) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.valves.ErrorReportValve.invoke (ErrorReportValve. java: 81) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.core.StandardEngineValve.invoke ( StandardEngineValve. java: 87) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .catalina.connector.CoyoteAdapter.service (CoyoteAdapter. java: 342) [tomcat -embed-core-8.5.29.jar: 8.5.29] в организации. apache .coyote.http11.Http11Processor.service (Http11Processor. java: 803) [tomcat-embed-core-8.5.29.jar : 8.5.29] at org. apache .coyote.AbstractProcessorLight.process (AbstractProcessorLight. * 1 093 *: 66) [tomcat-embed-core-8.5.29.jar: 8.5.29] в орг. apache .coyote.AbstractProtocol $ ConnectionHandler.process (AbstractProtocol. java: 790) [tomcat-embed- core-8.5.29.jar: 8.5.29] в орг. apache .tomcat.util. net .NioEndpoint $ SocketProcessor.doRun (NioEndpoint. java: 1459) [tomcat-embed-core-8.5. 29.jar: 8.5.29] at org. apache .tomcat.util. net .SocketProcessorBase.run (SocketProcessorBase. java: 49) [tomcat-embed-core-8.5.29.jar: 8.5. 29] в java .util.concurrent.ThreadPoolExecutor.runWorker (неизвестный источник) [na: 1.8.0_45] в java .util.concurrent.ThreadPoolExecutor $ Worker.run (неизвестный источник) [na: 1.8.0_45] в орг. apache .tomcat.util.threads.TaskThread $ WrappingRunnable.run (TaskThread. java: 61) [tomcat-embed-core-8.5.29.jar: 8.5.29] в java .lang .Thread.run (Неизвестный источник) [na: 1.8. 0_45]
Все работает нормально, за исключением того, что при отправке формы функция saveConsumer отлично работает оператор sysout , но consumerServiceInterface.saveConsumer ( conusmerBinder.getBean ()) выдает нулевую ошибку