• 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

convertDateTime

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<h:inputText value="#{policy.testDate}" id="received">
<f:convertDateTime pattern="dd-MMM-yyyy"/>
</h:inputText>

when using the above code in a jsp page I get the following error

java.lang.IllegalArgumentException: argument type mismatch

This occurs when testDate maps to a java.sql.Date object in the backing bean. It seems to work ok when I change testDate to a java.util.Date object.

Question, does convertDateTime only work with a java.util.Date object. I thought it should work with java.util.Date and all its subclasses which would include java.sql.Date.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the problem is that you have 3 'M's in your pattern.

That would throw an IllegalArgumentException from the SimpleDateFormat's applyPattern() method.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gary stines:
<h:inputText value="#{policy.testDate}" id="received">
<f:convertDateTime pattern="dd-MMM-yyyy"/>
</h:inputText>

when using the above code in a jsp page I get the following error

java.lang.IllegalArgumentException: argument type mismatch

This occurs when testDate maps to a java.sql.Date object in the backing bean. It seems to work ok when I change testDate to a java.util.Date object.

Question, does convertDateTime only work with a java.util.Date object. I thought it should work with java.util.Date and all its subclasses which would include java.sql.Date.



It is because, internally getAsObject() in converter performs SimpleDateFormat_instance.parse() operation which return a java.util.Date type of object. Now an java.sql.Date type reference can't hold a java.util.Date type of object (only parent can hold a reference to child object)
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
I believe the problem is that you have 3 'M's in your pattern.

That would throw an IllegalArgumentException from the SimpleDateFormat's applyPattern() method.



Using 3 'M's is fine.

SimpleDateFormat spec mentions

Month: If the number of pattern letters is 3 or more, the month is interpreted as text; otherwise, it is interpreted as a number.

[ February 16, 2005: Message edited by: K Varun ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why this converter won't support a java.sql.Date. I think it might be rooted in the common bean utils library.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gary VanMatre:
I don't understand why this converter won't support a java.sql.Date. I think it might be rooted in the common bean utils library.



When the DateTimeConverter gets a string it tries to convert it into Date object as follows :

1. It takes the input in the form of "String"
2. Passes the String to getAsObject method
3. getAsObject method, ultimately calls SimpleDateFormat.parse(String str) method and return the output of this method to you.

Now you want the output to be of java.sql.Date type but if you see the
API here, "parse" method returns java.util.Date type of object.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic