Showing posts with label Search Form in ADF. Show all posts
Showing posts with label Search Form in ADF. Show all posts

Sunday, 1 November 2015

ADF BC: Part 4: Search Form. Absolute Basics

          In the last posts, we saw how to build simple LOVs and Cascading LOVs declaratively, without writing any code. In this post we will see how to build Search form using ADF BC.
Search forms are one of the most common requirement that we come across. ADF BC implement it using View Criterias on a VO. 
           The advantage of such an approach is that you can have many search criterias on the same VO, e.g., one can search by All the searchable fields of an Employees VO, or By Manager's Name or Employee's Name or by Hire Date etc....


Just breeze through the wizard by pressing Next until 2 projects Model and ViewController are created as below:


Now right click on Model project and invoke the "Create Business components from Tables" wizard. Chose the HR connection and select the Employees table.


Create EmployeesVO in the Entity-based View object


No need to select the Read only VO. Chose the default setting on Application Module. Keep clicking next and Finish. Finally the Model should look like below:


Now create a jsf page. Right Click on ViewController -> New -> "Page" as shown below:



In the next screen give FileName as SearchEmoployee.jsf (Even if you chose .jspx in 11g it should not give any issues).


Now goto the Data Control and Drag and Drop the "All Queriable Attributes" onto the page. From the resultant popup chose Query -> ADF Query Panel with Table.


This will bring "Create Table" screen where you can select what all columns to be displayed onto the Table. You can also chose if you should only allow "Single Row" or "Multiple Rows", Filter and sorting option.

 

Just run the page. It should show like below:


Try following things to get a hang of the Search Form and table. 
a) Press on Search and it should give all the rows. 
b) Give values on the filters and press ENTER to filter the values. 
c) Hover over the column and you will see Sorting icons.
d) Press on "Any" and give multiple search fields to see that it acts like an "OR" condition.



e) Click on Advanced button and see how many options appearing like Contains, Is Blank etc.. You can also see Add fields to achieve OR condition on 1 column. Eg., find employees with Id 100 or 101 or 102...


This was absolute Basic of the Search capabilities of af:Query component. Its likely that you are almost never going to use this in its default form.

We can a lot of things with af:query like:
a) Execute Search by default.
b) Creating Other Query Criterias like Search By First Name and Last Name etc...
c) Making use of "Selectively Required" which means one of the fields must be given.
d) Making Search field Mandatory.
e) Removing Search fields while running.
f) Arranging fields in the Query Region.
and a lot more...


Please note this application is Done on 12c. 12.1.2 version. The steps should be similar on 11g as well.

Saturday, 21 September 2013

ADF Search Form; Date Search

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.


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: