In this Post we will make a simple Search Form.
But more importantly, we will see how to handle the Date Search on a Date Column. Normally users searche by Date and not Time (e.g., on 19th Sep How many Employees were created). Oracle stores time along with the date in its Date Types. So when a user searches with Date (which by Default has no Time Element so it passes 00:00:00 in the time element) ADF does not pull any records.
Create a table XX_EMPLOYEES and insert following data. Make sure that Time part is not Truncated while inserting the date.
But more importantly, we will see how to handle the Date Search on a Date Column. Normally users searche by Date and not Time (e.g., on 19th Sep How many Employees were created). Oracle stores time along with the date in its Date Types. So when a user searches with Date (which by Default has no Time Element so it passes 00:00:00 in the time element) ADF does not pull any records.
Create a table XX_EMPLOYEES and insert following data. Make sure that Time part is not Truncated while inserting the date.
Create a New Web Application with Name as DateSearch and give Prefix as "com.adf.datesearch". Chose default in the Next Screens and Finish.
Right Click on Model and Chose "Business Tier" -> "ADF Business Components" -> "Business Components from Tables" -> Query for the Table XX_EMPLOYEES -> Click Next -> In Updatatable VO Shuttle the EO to the Right Hand Side -> No Need to give anything in Read Only View -> Keep saying OK but make sure that the View XxEmployeesView is Added to a AM.
Finally the model should look like below:
Now the most Important Part, which is about the Date Search Issue.
An easy to resolve this is to include another column on VO Query and Truncate its time part using Trunc function. Goto VO -> Query -> Open the Query in Expert mode and add another Column name
trunc(XxEmployees.CREATION_DATE) ONLY_DATE as shown below in the screenshot.
Make sure that this is showing in the Attributes as below:
Right Click on AppModule and Run. Click on XxEmployeesView1 and Click on Search Icon (Blue Binoculars) and give the date on Only Date Prompt and hit Find.
Try the same with CreationDate and you will not get any records.
Now lets build a jsf page. Right Click on the ViewController Project -> New -> Web Tier -> JSF -> JSF Page -> Ok. On the resulting "Create JSF Page" give the Page Name "DateSearchPG.jspx" -> Ok.
Goto DataControl -> XxEmployeesView1 -> NamedCriteria -> Drag "All Queriable Attributes" onto the Page as shown below:
This will open another Dialog Box to Edit Table. Simply chose Ok.
Now run the page and Search with OnlyDate and you should get the results you want as shown below. However if you search by CreationDate nothing will show.
Note: For every VO Created, JDeveloper Automatically Create a Default "View Criteria" using all Queriable Attributes on a VO. Since All the Attributes by default are queriable so in the Query Component you will see all. Since the search is not done on IDs and certainly not on ROWID you can goto the XxEmployeesView.xml and change the ROWID, CreationDate, EmpId to non queriable.
Edit OnlyDate Attribute and change the Label to "Date Created" in Control Hints as shown below:
Run the page and do some Search on Date as shown below: