Problem with binding java.sql.Date to DateField

Hello,

I use JPAContainer and I have defined this column in my entity:


    private java.sql.Date startDate;
	
    public java.sql.Date getStartDate() {
		return startDate;
	}
	
	public void setStartDate (java.sql.Date startDate) {
		this.startDate = startDate;
	}

I want to bind the date to a DateField:

protected Item newItem;
protected FormLayout frlMain;
...
figBinder = new FieldGroup(newItem);

DateField datStartDate = new DateField("Termín zahájení");
figBinder.bind(datStartDate, "startDate");
frlMain.addComponent(datStartDate);

And I get an exception on line 7:


Caused by: java.lang.NullPointerException
	at com.vaadin.data.util.converter.DateToSqlDateConverter.convertToPresentation(DateToSqlDateConverter.java:59)
	at com.vaadin.data.util.converter.DateToSqlDateConverter.convertToPresentation(DateToSqlDateConverter.java:35)
	at com.vaadin.data.util.converter.ConverterUtil.convertFromModel(ConverterUtil.java:94)
	at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:708)
	at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:693)
	at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:629)
	... 53 more

Other bindings of VARCHAR or NUMERIC types to TextField works fine, but problem is to bind Date.

Could you advise me please?

To be sure I am inserting full log:

[INFO]
 Started Jetty Server
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[EL Info]
: 2013-10-03 16:31:18.194--ServerSession(25279313)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Info]
: 2013-10-03 16:31:18.653--ServerSession(25279313)--file:/home/marek/programovani/workspace/ranna01/target/classes/_ranna login successful
X 03, 2013 4:31:22 ODP. com.vaadin.server.DefaultErrorHandler doDefault
SEVERE: 
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
	at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:214)
	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:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.reflect.InvocationTargetException
	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.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
	... 33 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in eu.ranna.ranna01.ui.CommonTableLayout$3 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.Button.fireClick(Button.java:368)
	at com.vaadin.ui.Button$1.click(Button.java:57)
	... 38 more
Caused by: com.vaadin.data.Buffered$SourceException
	at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:637)
	at com.vaadin.data.fieldgroup.FieldGroup.bind(FieldGroup.java:265)
	at eu.ranna.ranna01.ui.ProjectEditor.initBinder(ProjectEditor.java:42)
	at eu.ranna.ranna01.ui.CommonEditor.<init>(CommonEditor.java:37)
	at eu.ranna.ranna01.ui.ProjectEditor.<init>(ProjectEditor.java:12)
	at eu.ranna.ranna01.ui.ProjectLayout.initEditor(ProjectLayout.java:58)
	at eu.ranna.ranna01.ui.CommonTableLayout$3.buttonClick(CommonTableLayout.java:131)
	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)
	... 42 more
Caused by: java.lang.NullPointerException
	at com.vaadin.data.util.converter.DateToSqlDateConverter.convertToPresentation(DateToSqlDateConverter.java:59)
	at com.vaadin.data.util.converter.DateToSqlDateConverter.convertToPresentation(DateToSqlDateConverter.java:35)
	at com.vaadin.data.util.converter.ConverterUtil.convertFromModel(ConverterUtil.java:94)
	at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:708)
	at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:693)
	at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:629)
	... 53 more

Isn’t your date
null?

It is, because I open empty form to input a new record, but the fields are binded to empty Item already.

I use the same method if I bind
null
String propertyId to TextField and it works.

It seems to be bug in Vaadin. You can work around it by setting a default value to your entity: [code]
private java.sql.Date startDate = new Date(0l);

public java.sql.Date getStartDate() {
    return startDate;
}

public void setStartDate (java.sql.Date startDate) {
    this.startDate = startDate;
}

[/code]

Which Vaadin version are you using? This should be fixed in 7.1.6; see ticket
#12284
.

Thank you both!

I have version 7.1.5, so I am going to upgrade it!