I am trying to use the Java 8 time functionalities and have a problem.
First needed the Util date converted into Instance followed by using the Duration API.
Here is my code in controller:
if("startDate".equals(e.getProperty()) || "endDate".equals(e.getProperty())){
LocalDate fDate = productionPlanResourceDs.getItem().getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate tDate = productionPlanResourceDs.getItem().getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
long days = Duration.between(fDate, tDate).toDays();
productionPlanResourceDs.getItem().setDuration(days);
productionPlanResourceDs.refresh();
}
I am getting the following error in the line …“LocalDate fDate = …”
java.lang.UnsupportedOperationException
at java.sql.Date.toInstant(Date.java:304)
at com.company.gms.gui.productionplan.ProductionPlanEdit.lambda$init$1(ProductionPlanEdit.java:91)
at com.company.gms.gui.productionplan.ProductionPlanEdit$$Lambda$103/110614814.itemPropertyChanged(Unknown Source)
at com.haulmont.cuba.gui.data.impl.AbstractDatasource$ItemListener.propertyChanged(AbstractDatasource.java:333)
at com.haulmont.chile.core.model.impl.AbstractInstance.propertyChanged(AbstractInstance.java:46)
at com.company.gms.entity.ProductionPlanResource.setStartDate(ProductionPlanResource.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.haulmont.chile.core.model.utils.MethodsCache.invokeSetter(MethodsCache.java:58)
at com.haulmont.chile.core.model.impl.AbstractInstance.setValue(AbstractInstance.java:126)
at com.haulmont.cuba.core.entity.BaseGenericIdEntity.setValue(BaseGenericIdEntity.java:228)
at com.haulmont.chile.core.model.impl.AbstractInstance.setValue(AbstractInstance.java:112)
at com.haulmont.chile.core.model.utils.InstanceUtils.setValueEx(InstanceUtils.java:178)
at com.haulmont.cuba.web.gui.components.WebDateField.updateInstance(WebDateField.java:284)
at com.haulmont.cuba.web.gui.components.WebDateField.lambda$createDateValueChangeListener$50693cdd$1(WebDateField.java:101)
at com.haulmont.cuba.web.gui.components.WebDateField$$Lambda$89/836028012.valueChange(Unknown Source)
at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1169)
at com.vaadin.ui.DateField.fireValueChange(DateField.java:643)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:577)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:473)
at com.vaadin.ui.DateField.setValue(DateField.java:719)
at com.haulmont.cuba.web.toolkit.ui.CubaDateField.setValue(CubaDateField.java:66)
at com.vaadin.ui.DateField.changeVariables(DateField.java:618)
at com.haulmont.cuba.web.toolkit.ui.CubaDateField.changeVariables(CubaDateField.java:74)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:609)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:428)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:79)
at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.lambda$synchronizedHandleRequest$82(CubaVaadinServletService.java:306)
at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler$$Lambda$27/391421285.call(Unknown Source)
at com.haulmont.cuba.web.sys.CubaVaadinServletService.withUserSession(CubaVaadinServletService.java:187)
at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.synchronizedHandleRequest(CubaVaadinServletService.java:306)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:369)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:242)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
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)