I am trying to use the calendar component bound to properties of type java.sql.Date and java.sql.Timestamp. I have created the necessary converters from String to these datatypes, and specified the converters to the calendar component, but with these bindings, the calendar never sets the value. It gets the existing value, and displays it but ignores the pattern.
Is it, or should it be, possible, to use the calendar component with java.sql.Date and other types that inherit from java.util.Date?
Calendar with java.sql.Date
Is there a specific reason why you need to use java.sql.Date?
Anyways, as you already mentioned, java.sql.Date inherits from java.util.Date which makes it possible to cast a java.sql.Date to a java.util.Date:
Accordingly, you could store your Date using java.sql.Date in your Bean and add another get-Method which returns a java.util.Date using a cast of the Bean's attribute and a setter method which converts the java.util.Date parameter to the java.sql.Date.
for your calendar you can use the dateBean.calendarDate-Property
Anyways, as you already mentioned, java.sql.Date inherits from java.util.Date which makes it possible to cast a java.sql.Date to a java.util.Date:
Code: Select all
java.util.Date date1 = new Date();
java.sql.Date date2 = (java.util.Date)date1;
Code: Select all
class DateBean {
java.sql.Date date;
java.util.Date getCalendarDate() {
return (java.util.Date)this.date;
}
void setCalendarDate(java.util.Date date) {
this.date = new java.sql.Date(date.getTime());
}
java.sql.Date getDate() {
return this.date;
}
void setDate(java.sql.Date date) {
this.date = date;
}
}
Can I have a converter that takes the calendar's java.util.Date and convert it to java.sql.Date before it is set in the property?
=== free slots ===
-
- Information
-
Who is online
Users browsing this forum: No registered users and 24 guests