Working with Dates in the Model Layer

 

In ADF applications, model data is surfaced to the view and controller layers through data control objects implemented for each type of data provider. The Oracle ADF data controls provide a consistent mechanism for clients and web application controllers to access data and actions defined by these diverse data-provider technologies, including Oracle ADF Business Components, JavaBeans, EJB session beans, Web Services, etc.

No matter if you are using the BC4J components or creating your own objects, the date object that the model layer must provide to the controllers is oracle.jbo.domain.Date

 

If you are using JavaBeans or EJBs you should convert the dates from the Java date format to oracle.jbo.domain.Date if necessary, for example:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
...
DateFormat formatter;
formatter = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date date;
date = formatter.parse("25/10/2010");
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate); 


If you try to send a different date object from the model layer you can get an error like the following:

DateError.jpg
 

 

To change the date format in BC4J components like View Objects or Entity Objects, you can execute the following steps:

1. Open the component

2. Go to the Overview tab

3. Go to the Attributes section at the left

4. Double click on the date field, the Edit Attribute window will open

5. Go to the Control Hints section at the left

6. Select format date "Simple Date"

7. Enter the desired format on the Format property

8. Click Apply

9. Click Ok (the Edit Attribute window will close) 

bc4jdateformat.jpg
 

 

Note that dates in both BC4J and other objects that you can develop for the model layer (like EJBs or other Java classes) must be formatted with the Java date format, whose usage can be seen here, but finally the date sent to the ViewController must be an object of type oracle.jbo.domain.Date

 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About


Principal Technical Support Engineer in the Exalogic Enterprise Support Team (EEST).

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today