简体   繁体   中英

Adf column filter: which format does ADF use to generate the where clause in the VO's query?

TLDR; is there a way to understand at runtime which format is ADF using for dates behind the scenes? In particular the format used to render dates in dynamically generated sql code?

In the Oracle ADF Application I'm working on there are several table filters (by that I mean the field over the column in which I can write text/number/dates to query the table).

Filtering this way, the framework modifies the query of the View Object, adding the appropriate where clause. On the page there's also a button "Select all" that allows me to select all the data that's rendered in the table (there is a selection checkbox).

In the specific case, the query from the VO is used to aim two different goals:

  • update the rendered data in the table
  • if I press the "select all" button a function in the backend database is called (callable statement calling the function), passing as a parameter the query.

The first task is successfully reached (as the table is visually updated), but we had an issue with the second one. The backend function uses the query to select all the extracted data (as iterating in ADF with java would be too slow). The problem is that the where clause isn't correctly generated for the backend database (which is also oracle).

Basically the generated WHERE clause (which was added to VO's query automatically by the framework) was

WHERE record_date = '2020-10-12'

which I had to change to

WHERE record_date = to_date('2020-10-12', 'YYYY-MM-DD')

in order to have it correctly executed by the Oracle Db.

So now it's working (yay), but my concern is: isn't it dangerous to assume the date format will be 'YYYY-MM-DD' on every application's instance?

I think this 'YYYY-MM-DD' is the format in which ADF is managing dates (as the value is written as '2020-10-12' in the query).

But is there a way to understand at runtime which format is ADF using for dates behind the scenes? Or does it always use 'YYYY-MM-DD', or am I completely off-road and the storage format is another and I should ask which format does it use to render dates? But dates on page are visually rendered in another way:/

Sorry for my lack of expertise and have a nice day!

Update

The value of the query field, which I'm getting by calling

this.getNamedWhereClauseParams().getAttribute('vc_temp_1');

is of class

oracle.jbo.domain.Date

and by printing it I obtain the date in format YYYY-MM-DD.

Would it be possible that the framework was simply using Date.toString? This would raise another question: how can I be sure of the pattern used by Date.toString? The documentation isn't clear about it (and it says that it should be used only in development, so this is quite a remote scenario).

What you named 'Filter' is called 'Query by Example' or QBE in short. See the doc for more info.

You can change the query passed to the server using a bean method. Look at eg JDev 12.2.1.3: Multi select component table filter for a sample.

Using dates in ADF is always dependent on the current user's settings. If the user don'T use a specific locale the default is 'yyyy-mm-dd'. This can be changed at different points, starting by the entity objects, view objects a,d finally in the UI by using converters.

The best way to use dates depends on the use case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM