Date Custom Datatype

Hi CUBA team,

I have a requirement:
users input the day of the month to the field. then I need format the value to date, the month and year value will be the current ones.

So, I am trying to create a custom datatype, but even I don’t implement any methods, it still not working.



public class DayDatatype extends DateDatatype {
    public static final String NAME = "day";

    public DayDatatype(Element element) {
        super(element);
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String toString() {
        return NAME;
    }
}
and I got exception like this:


java.lang.UnsupportedOperationException: Can't create field "date" with data type: day
	at com.haulmont.cuba.gui.components.AbstractFieldFactory.createField(AbstractFieldFactory.java:129)
	at com.haulmont.cuba.web.gui.components.WebFieldGroup.createField(WebFieldGroup.java:445)
	at com.haulmont.cuba.web.gui.components.WebFieldGroup.createFields(WebFieldGroup.java:419)
	at com.haulmont.cuba.web.gui.components.WebFieldGroup.setDatasource(WebFieldGroup.java:402)
	at com.haulmont.cuba.gui.xml.layout.loaders.FieldGroupLoader.loadComponent(FieldGroupLoader.java:496)
	at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:37)
	at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:76)
	at com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader.loadComponent(WindowLoader.java:82)
	at com.haulmont.cuba.gui.WindowManager.createWindow(WindowManager.java:417)
	at com.haulmont.cuba.gui.WindowManager.openEditor(WindowManager.java:702)
	at com.haulmont.cuba.web.WebWindowManager.openEditor(WebWindowManager.java:157)
	at com.haulmont.cuba.gui.components.WindowDelegate.openEditor(WindowDelegate.java:250)
	at com.haulmont.cuba.web.gui.WebWindow.openEditor(WebWindow.java:444)
	at com.haulmont.cuba.gui.components.actions.EditAction.internalOpenEditor(EditAction.java:232)
	at com.haulmont.cuba.gui.components.actions.EditAction.actionPerform(EditAction.java:225)
	at com.haulmont.cuba.web.gui.components.WebAbstractTable.handleClickAction(WebAbstractTable.java:779)
	at com.haulmont.cuba.web.gui.components.WebAbstractTable.lambda$initComponent$4fd149ee$1(WebAbstractTable.java:663)
	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:498)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)
	at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1037)
	at com.vaadin.ui.Table.handleClickEvent(Table.java:3221)
	at com.vaadin.ui.Table.changeVariables(Table.java:2998)
	at com.haulmont.cuba.web.toolkit.ui.CubaTable.changeVariables(CubaTable.java:252)
	at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:634)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:468)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:418)
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90)
	at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.lambda$synchronizedHandleRequest$0(CubaVaadinServletService.java:314)
	at com.haulmont.cuba.web.sys.CubaVaadinServletService.withUserSession(CubaVaadinServletService.java:196)
	at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.synchronizedHandleRequest(CubaVaadinServletService.java:314)
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1422)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:384)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:276)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:185)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:108)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:95)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

I create the datatype based on project https://github.com/knstvk/cuba-sample-datatype I changed the order date to my DayDatatype Gabriel

Hi Gabriel,

Unfortunately, parsing of dates is performed in JavaScript on the browser side and cannot be customized for the current implementation of the DateField component. As I said before, we will consider such option in the future.

OK, I got it, thank you very much, Konstantin.

Hi Gabriel,

The FiedlGroup component is incapable to create fields for custom datatypes automatically - it just doesn’t know how to do it. So use a custom field and create a component for your field programmatically - see FieldGroup.setComponent() method.

Hi Konstantin,

Thank you very much for your reply.

I want to know, is it possible that when a user inputs the day of the month, then the current month and year auto filled.

can you give me some advice, please?

Best Regards.
Gabriel

Do you mean in a standard DateField? Not sure. What about just initializing the field with the current date beforehand?

Hi Konstantin,

Actually, that field is nullable, what I want is that only when the users focus on this field and input the day of the month and then when the field lose focus, then auto fill the month and year.

Gabriel

Hi Gabriel,

I think it makes sense as a standard behavior, so I’ve created an issue for improvement, see the link to YouTrack. I will also discuss with the team how you could achieve this in the current implementation.

Thank you very much :slight_smile:

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9180