|
#1
|
|||
|
|||
|
Hi
How to set a date value on bean ? <bean id="beanid" class="BeanClass"> <property name="date" value="2008-03-01"/> </bean> |
|
#2
|
|||
|
|||
|
By default there isn't a date PropertyEditor registered. PropertyEditors are the objects which convert strings into other object types. There are many PropertyEditors registered by default. Things like numbers, Class, etc. So you need to create a CustomDateEditor and then register it with your ApplicationContext using CustomEditorConfigurer. Take a look here for more information.
__________________
Bill |
|
#3
|
|||
|
|||
|
Just add the below configuration right after your <beans> definition.
This would take care of registering the CustomDateEditor with the SHORTdate format (mm/dd/yy). PHP Code:
With this in place, you can now configure String-values for Date (java.util.Date) properties in your Bean definition file: PHP Code:
PHP Code:
The concern that I have with this approach is using hardcoded '3' for SHORT in the Bean configuration. This doesn't seem great idea. (What if Sun decides to change this value to something else?).
__________________
Som ![]() ---------- Java Admirer! |
|
#4
|
|||
|
|||
|
PHP Code:
|
|
#5
|
|||
|
|||
|
maby factory method should be static
|
|
#6
|
|||
|
|||
|
Hi,
I'm facing the exact same problem. GregorianCalendar.getTime() is not static, it's a regular getter. How to reference not GregorianCalendar bean but it's getTime() method return value ? this doesn't work ![]() PHP Code:
|
|
#7
|
|||
|
|||
|
Reference documentation - 3.2.3.2.3. Instantiation using an instance factory method
|
|
#8
|
|||
|
|||
|
It works !
I had missed this in the doc. I was stupidly associating "factory" word with "static" method (wich is really stupid), so I jumped over this paragraph ![]() final conf: PHP Code:
|
|
#9
|
|||
|
|||
|
Don't blame yourself, everyone makes a mistakes
![]() This forum is intended to be a place where people can help to each other. Believe me, it was not hard for me to point to the necessary documentation location
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|