2 customers asked me this week how to specify a second date pattern for an 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).
<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>
(...)
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)
Hi,
but when i select the date from the component its displaying like this .I want to display the date in this format dd/mm/yyyy. Below is the code which i declared in the JSPX.
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
Posted by Vimalan Balan | April 9, 2008 9:09 AM
Posted on April 9, 2008 09:09
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.
Posted by Didier Laurent | April 9, 2008 10:01 AM
Posted on April 9, 2008 10:01
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
Posted by Vimalan Balan | April 19, 2008 9:12 AM
Posted on April 19, 2008 09:12
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.
Posted by Didier Laurent | April 19, 2008 12:46 PM
Posted on April 19, 2008 12:46
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.
Posted by Sergio Calvo | October 16, 2008 1:18 PM
Posted on October 16, 2008 13:18
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.
Posted by Didier | October 19, 2008 10:58 PM
Posted on October 19, 2008 22:58