20 October 2013

Problem with date field format in ADF

When you have some requirement to format the date field in ADF application, You may face the following problem if you have given the format at View object attribute level.



The attribute in query panel and result in table will be shown perfectly, but when you click on date picker of table filter of HireDate column and select some date you can see the format is not coming proper.

 In order to resolve this you have to give <af:convertDateTime> format for filter facet as "dd/MM/yyyy" as shown below.

<af:column sortProperty="HireDate" filterable="true" sortable="true"
                       headerText="#{bindings.EmployeesVO1.hints.HireDate.label}"
                       id="resId1c5">
              <f:facet name="filter">
                <af:inputDate value="#{vs.filterCriteria.HireDate}" id="id1">
                 <af:convertDateTime pattern="dd/MM/yyyy"/>
                 </af:inputDate>
              </f:facet>
              <af:outputText value="#{row.HireDate}" id="ot1">
                <af:convertDateTime pattern="#{bindings.EmployeesVO1.hints.HireDate.format}"/>
              </af:outputText>
 </af:column>

Now you can see the date field is coming proper.

Now after this you may face another problem. If you are using the same attribute in form for entering date you can notice one strange behavior. Whatever be the value in field the date picker always highlight the current date. It will not highlight the date selected in attribute value.


Now how we can resolve this issue.
 Putting <af:convertDateTime pattern="dd/MM/yyyy"/> will also not work in this case.

In order to resolve this we have to do the following things,

Go to your view object attribute tab and select "Add attribute from Entity"


Now don't put the date format in this newly added attribute.

Now put this attribute on Jspx or jsff page for form.

 <af:inputDate value="#{bindings.HireDate1.inputValue}"
                        label="#{bindings.HireDate1.hints.label}"
                        required="#{bindings.HireDate1.hints.mandatory}"
                        shortDesc="#{bindings.HireDate1.hints.tooltip}"
                        id="id2">
            <f:validator binding="#{bindings.HireDate1.validator}"/>
            <af:convertDateTime pattern="#{bindings.HireDate1.format}"/>
</af:inputDate>

Now put the format here at page level.

<af:inputDate value="#{bindings.HireDate1.inputValue}"
                        label="#{bindings.HireDate1.hints.label}"
                        required="#{bindings.HireDate1.hints.mandatory}"
                        shortDesc="#{bindings.HireDate1.hints.tooltip}"
                        id="id2">
            <f:validator binding="#{bindings.HireDate1.validator}"/>
            <af:convertDateTime pattern="dd/MM/yyyy"/>
</af:inputDate>

Now run your page and seethe date picker will highlight the selected date in field not the current date.


That's all :) Happy coding.

1 comment:

  1. putting af: format is not possible in my case. I am directly exposing a VO as ADF REST API resource. So is it possible to show particular date format like MM/yyyy. Even though I changed the VO attribute date format, its still not getting reflected in REST API output.

    ReplyDelete