f:converDateTime pattern="MM/dd/yy".

When i use f:converDateTime with pattern MM/dd/yy and if user enters

date as '01/01/07', converter is converting it to 01/01/0007. While expected behaviour is '01/01/2007'.

Can some body please give solution on it?

Thanks.

Vipul Dave.

Cignex Tech Inc,

San Jose, CA

[311 byte] By [tbehkfhkea] at [2007-11-27 11:59:19]
# 1

Which JSF implementation and version are you using?

BalusCa at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Could you try pattern="MM/dd/yyyy"?

I think it may work.

penquina at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi...BaluC,

On the other hand,

if the pattern is "MM/dd/YYYY" & the user enters 7/7/07, the date is re-renderd as 07/07/0007.

Which JSF version & implementation work or has this issue fixed?

Regards,

Praveen

pmohanana at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Looking to the SimpleDateFormat API [1] this is expected behaviour. Best way is to change the required input to MM/dd/yyyy and let the user enter exact that value, with 4 year digits.

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

BalusCa at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Thanks for the reply everybody.

Before validator , Converer is getting invoked and it is converting 'yy' to 'yyyy'.

Is there anyway to enforce user to enter 'yyyy', i mean 'MM/dd/yyyy' ?

Vipul Dave,

Cignex Tech. Inc,

San Jose, CA.

Message was edited by:

tbehkfhke

Message was edited by:

tbehkfhke

tbehkfhkea at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Add a LengthValidator using f:validateLength or write a custom date validator (preferred).

BalusCa at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hi...BaluS,

Will the f:validatelength get fired first or the converter?

Regards,

Praveen

pmohanana at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanks Balu C.

I am writting a custom converter by extending javax.faces.convert.DateTimeConverter class.

Can you please tell me which are the method i need to override to make it work ?

Vipul Dave.

Cignex Tech Inc,

San Jose, CA.

tbehkfhkea at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

You need to override getAsObject() and getAsString(). The getAsObject() will be invoked when a value needs to be converted from the view (String in input field, clientside) to the controller (Object in backing bean, serverside). The getAsString() will be invoked when a value needs to be converted from the controller to the view.

This article might be of interest: http://balusc.xs4all.nl/srv/dev-jep-djl.html

BalusCa at 2007-7-29 19:24:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...