I am using JSF 2.0 and RichFaces 3.3. In my View user will pich a date from a calendar. Tag used is <rich:calendar>
. This is mapped in backing bean with Date
object. However this field is optional and hence when user does not select a date the backing bean getter for this particular entry returns null
, which is right.
My problem is that I have to store this date in DB. So before storing I am type casting it in this manner:
if (newProfile.get(Constants.DETAILS_EXPIRY_DATE_1).equals(null)) {
this.cStmt.setDate(15,null);
} else {
java.sql.Date sqlDate = new java.sql.Date(((java.util.Date)newProfile.get(Constants.DETAILS_EXPIRY_DATE_1)).getTime());
this.cStmt.setDate(15,sqlDate);
}
However it is throwing a NullPointerException
in the if
condition. I want to insert null
value in DB when user does not select a date. How can I do this?