• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Unable to set Date field in ManagedBean

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone have a solution to this:

"I have a simple bean with a java.util.Date property named "dateOfBirth" with
get/set methods.

I tried setting its value through JSF's configuration file:

...
<managed-property>
<property-class>java.util.Date</property-class>
<property-name>dateOfBirth</property-name>
<value>02-15-2005</value>
</managed-property>
...

I'm getting:
Feb 15, 2005 11:38:09 AM com.sun.faces.application.ApplicationAssociate createAndMaybeStoreManagedBeans
SEVERE: Managedbean user could not be created Can't instantiate class: '02-15-2005'.
javax.faces.FacesException: Can't instantiate class: '02-15-2005'.

I tried various date formats but haven't succeeded.
Perhaps there is no internal converter for this type of class?"


This is on a Sun Thread but no one really responeded. I am having the same problem. Anyone have a solution?
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems the java.util.Date condition isn't handled in "ManagedBeanFactory.java". Either you need to fix it
Or, Better use Constructor of your backing bean for initialization
[ March 08, 2005: Message edited by: Varun Khanna ]
 
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
This method is the real culprit, is not handling Date condition and hence returning CANT_INSTANTIATE_CLASS_ERROR_MESSAGE_ID.
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I did put it in the constructor in my backing bean, but i can only initialize it once. I'm doing a 1/2 working demo for a new website and I have an event object that has this event date attribute. Until I write all the backend code, i can only initialize this to one date. The site I'm writing will use a DataGrid to display an ArrayList (another managed bean) of these event Managed Beans. Any suggestions? I could hardcode some logic to use different dates. Don't know the best approach.
 
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 Jason Milliron:
Thanks. I did put it in the constructor in my backing bean, but i can only initialize it once.


The first approach would also have initialized it once only.
<managed-property> is an initializing paramter.


I'm doing a 1/2 ... Any suggestions? I could hardcode some logic to use different dates. Don't know the best approach.


I am not able to get you. Can you re-explain.
[ March 08, 2005: Message edited by: Varun Khanna ]
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<managed-property> is an initializing paramter



I didn't think I could initialize a java.util.Date using managed-property. I had to hard code it in the constructor for the actual backing bean.

The 1/2 thing i was talking about was that right now, i'm in phase 1 for this project. This is basically just a working prototype. All my actions are hard coded and not coming from action methods. At this point all my data is static and not coming from the database.

any other ideas?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can do this in your JSF file

in your bean

take care of Java.util.Date and Java.sql.Date
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your help. I actaully had the two code parts written like that but you mentioned

take care of Java.util.Date and Java.sql.Date

. Did you mean to go into the method getConvertedValueConsideringPrimitives() and handle the Date part of it? If that's what you meant, i would have to get teh jsf source code and modify that, correct? Then re-zip it and then use that jar file? Sorry for all the responses, i really appreciate it.
 
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 Jason Milliron:
Thanks for all your help. I actaully had the two code parts written like that but you mentioned . Did you mean to go into the method getConvertedValueConsideringPrimitives() and handle the Date part of it? If that's what you meant, i would have to get teh jsf source code and modify that, correct? Then re-zip it and then use that jar file? Sorry for all the responses, i really appreciate it.



You can change the source code, but if tomorrow you migrate to a higher JSF version, it's going to be pain. There can be other potential problems too such as migration to another server etc.

I won't recommend you to touch the JSF source code, especially to implement this functionality. Use the constructor for initialization purpose.
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for all your help.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic