Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar java.util.date & sql.date  RSS feed

 
Chris Ernst
Ranch Hand
Posts: 37
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

I have a calendar picker in my JSF. I know that PrimeFaces works with java.util.date.
But I wanna save this date in a MySQL DB, I know that i have to convert the date and this is not the Problem.
The Problem is, I want to make it possibal that no date have be must set like NULL date.
When I do this I get a NullPointerException :(
Currently I work with a fake date wich i set in my getter/setter and that is verry dirty

thank you

cheers

Chris
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use an ORM such as JPA, you can define the Entity class with column definitions like this one:


That will cause any null date values to bounce when a request is made to write the record to the database and will also handle the dates in an intelligent and DBMS-independent way. You can also amp things up by adding a @Column annotation with "nullable=false" on it.

If you have the right options set, this non-null feature percolates up into the JSF code as well.

Note, however, that HTML web pages do not support Null values - JSF will convert them into empty strings before rendering them. It's recommended that you use the "required="true"" attribute on your date control if you want to ensure a valid date. You might also want to limit date ranges.
 
Chris Ernst
Ranch Hand
Posts: 37
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
l'll try it tomorrow at work. But i want that the user can choose to set a date or not. Its for reserving items and when he sayed I bring it back on 24.12.2020 or he don't know....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!