« JDeveloper 10.1.3.2 (WebCenter) Production | Main | NoSuchMethodError - AdfFacesContextFactory.createContext »

How To Specify a Second Date Pattern in ConvertDateTime


2 customers asked me this week how to specify a second date pattern for an af:selectInputDate

(...)
<af:selectInputDate value="#{bindings.Hiredate.inputValue}"
                    label="#{bindings.Hiredate.label}"
                    required="#{bindings.Hiredate.mandatory}">
   <af:validator binding="#{bindings.Hiredate.validator}"/>
   <f:convertDateTime pattern="#{bindings.Hiredate.format}"/>
</af:selectInputDate>
(...)
Note the f:convertDateTime with the pattern attribute that will pick the Date format pattern you specified at the Entity Object level (or View Object).

This is not possible directly with the JSF Core <f:convertDateTime>.
However, this can be achieved with our own implementation <af:convertDateTime> that includes a property secondaryPattern,
that will be used as a second attempt to parse a string representing the date, if the primary pattern fails:
(...)
<af:convertDateTime pattern="#{bindings.Hiredate.format}"
                    secondaryPattern="ddMMyyyy"/>
(...)

For more information about the <af:convertDateTime>, click [Here]
Your entry in the Pattern and SecondaryPattern should respect the pattern syntax specified by the java.text.SimpleDateFormat.
You can test your pattern is valid in http://www.fileformat.info/tip/java/simpledateformat.htm
 

Comments (6)

Vimalan Balan:

Hi,

I want to display the date in this format dd/mm/yyyy. Below is the code which i declared in the JSPX.


     binding="#{backing_POMasterDetail.poRequestedDateH}"

     validator="#{backing_POMasterDetail.assignedDateValidator}">

    

    


but when i select the date from the component its displaying like this .

For Example : "09/47/2008", if i reload the page again and selecting the date its displaying some junk values in month column.

Thanks & Regards
Vimalan Balan

Didier Laurent:

Hi Vimalan,

thanks for reading my blog.

Your pattern is incorrect.

In 'dd/mm/yyyy', 'mm' represents the minutes, not the months, represented by 'MM'.
You can check it with the following pattern: "dd/MM/yyyy HH:mm:ss" that will display the months and the minutes:
f.ex. "16/04/2008 16:47:08"

So just change your pattern to "dd/MM/yyyy" and it will work.

Please note that my blog was about adding a second pattern to convertDateTime.

If your aim is to use one (and only one) pattern "dd/MM/yyyy", I would specify it at the ADF Business Components level, in the "Control Hints" tab of the date attribute, in "Format".

Regards,

Didier.

Vimalan Balan:

Dear Didier,

I am having a requirement based on selectInputDate. I want to display financial year in a text field based on the selectInputDate.

Ex: "19/04/2008" means i want to display "2008-2009" in another text field component. How can i do it. Kindly help me to get the date values in backing bean and then setting to another text field.

Thanks & Regards
Vimalan Balan

Didier Laurent:

Vimalan,

there is no pre-built format "fiscal year" in java.

You should add code in your backing bean to "calculate" the value of your "fiscal year" field depending of the value selected in the selectInputDate.

Regards,

Didier.

Sergio Calvo:

Hi Didier,

I want to achieve the same exact behavior you have in the first snippet on this page:

Load a pattern from an entity object, this time using your component. But it also seems to fail as the core jsf one.

Is it possible or not?

I do have a secondary pattern in place but still need to retrieve the primary provided by my bean.

Just in case I am using the myfaces trinidad flavor.

Thanks a lot, Sergio.

Hi Sergio,

yes, Trinidad has its own where you can define both properties "pattern" and "secondaryPattern".
For more information, see http://myfaces.apache.org/trinidad/trinidad-api/tagdoc/tr_convertDateTime.html

Regards,

Didier.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on February 1, 2007 6:35 PM.

The previous post in this blog was JDeveloper 10.1.3.2 (WebCenter) Production.

The next post in this blog is NoSuchMethodError - AdfFacesContextFactory.createContext.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle