• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar java.util.date & sql.date

 
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic