tags:

views:

191

answers:

1

I am developing a web application based on JSF technology. I use Eclipse as the IDE and using Apache Derby as a database.

When getting user input, I have one of the fields as a date field, i.e, Date of Birth. But when I update the database table, I get error report.

 Date Of Birth:
 <h:inputText value="#{employeeBean.dob}">
 <f:convertDateTime type="date" pattern="yyyy-mm-dd"/>
 </h:inputText>

Since the derby database accepts date in the format yyyy-mm-dd, I give input in the same way and have also used the same format.

This is the error I get.

 Exception while setting value for expression : #{employeeBean.dob} of component with 
 path : {Component-Path : [Class:javax.faces.component.UIViewRoot,ViewId: /homepage.jsp]
 [Class: javax.faces.component.html.HtmlForm,Id: j_id_jsp_996426310_1]
 [Class: javax.faces.component.html.HtmlInputText,Id: j_id_jsp_996426310_6]}

 Caused by:
 java.lang.IllegalArgumentException - Cannot convert 1/8/87 5:39 AM of type class
 java.util.Date to class java.sql.Date

Some one help me with this.

+3  A: 

Since JSF uses java.util.Date and derby perhaps expects java.sql.Date, you have to do something in order to acoomodate this gap:

  • change the type of the managed bean property to java.util.Date
  • if doing only the above doesn't work, convert between the two before saving. This can be done with the following constructor (Note that I don't know how you are going to persist the object to the database, so I'm guessing)

    java.sql.Date date = new java.sql.Date(jsfProvidedDate.getTime());
    
Bozho
Correct, that was the problem and I had the pattern also wrong as suggested by BalusC. I changed the type to java.util.Date, stored the variable in a string with the desired pattern and stored in the database. :-) Thank you.
Angeline Aarthi