Sometimes we need to implement custom search instead of using adf query component.
To implement custom search form , i have used a quite beautiful way to handle search and reset functionality for a View Object.
In this post i am taking Employees Table (Default HR Schema) to search and reset af:table.
To implement custom search form , i have used a quite beautiful way to handle search and reset functionality for a View Object.
In this post i am taking Employees Table (Default HR Schema) to search and reset af:table.
- First create a Fusion Web Application and create model (EO,VO and AM) using Employees table
- Now suppose we have to search on 4 fields (EmployeeId, FirstName, Email, Salary) , so for this i have created a new read only ViewObject from dual
- This VO from dual is created to be used as Search form on page
- Now to make search effective on Employees VO , i have created 4 bind variable for corresponding fields in Employees ViewObject
- Now i have created a ViewCriteria using these 4 bind variables to re-query ViewObject data
- This ViewCriteria will be executed each time when value of bind variable is changed, now this is the time to set value of bind variables, so i have dragged dual vo as a form on page, and added 2 button for Search and Reset
- To View Search Result , Employees Table is there on page
- Now to get value from Form Field to bean , i have created binding for all 4 fields in bean
- Now i have created ActionListener for Search button- in this code i have get value from page using component bindings and passed in Employees ViewObject's bind variable in order to execute viewCriteria.
- Once value is set in bind variable , view criteria is executed and Search result will be shown in resultant table- Run your application and see
public void searchButton(ActionEvent actionEvent) { searchAMImpl am = (searchAMImpl)resolvElDC("searchAMDataControl"); ViewObject empVo = am.getEmployees1(); empVo.setNamedWhereClauseParam("EmpIdBind", empIdPgBind.getValue()); empVo.setNamedWhereClauseParam("FirstNmBind", firstNmPgBind.getValue()); empVo.setNamedWhereClauseParam("EmailBind", emailPgBind.getValue()); empVo.setNamedWhereClauseParam("SalaryBind", salaryPgBind.getValue()); empVo.executeQuery(); }
- To reset values in table and search form, see the managed bean code of Reset button
- Click on reset button and page value are set to default
public void resetButton(ActionEvent actionEvent) { searchAMImpl am = (searchAMImpl)resolvElDC("searchAMDataControl"); ViewObject empVo = am.getEmployees1(); ViewObject attrVo=am.getattr1(); empVo.setNamedWhereClauseParam("EmpIdBind", null); empVo.setNamedWhereClauseParam("FirstNmBind", null); empVo.setNamedWhereClauseParam("EmailBind", null); empVo.setNamedWhereClauseParam("SalaryBind", null); empVo.executeQuery(); attrVo.executeQuery(); }
- This is how we can implement custom search using ADF components, you can apply validations, auto suggest feature etc while using this custom search
Cheers :-) Download Sample App
Hi Ashish
ReplyDeleteThanks for tutorial but i am not able to see filtered result on click of button
What could be the reason ?
Please help me
Smita have you applied viewCriteria in ApplicationModule ?
DeleteGo to Application Module --> click on viewObject--> click on Edit button on top right corner--> shuttle viewCriteria to selected side
And check again
Ashish
Thanku So much Ashish, It worked
DeleteHi Ashish, Could you please elaborate how did you create data binding? I'm new to ADF i tried following your attached sample application, but didn't understand the concept of data binding creation.
ReplyDeleteI will be grateful if you explain that.
Thanks a ton in advance ..Your blog is really awesome keep up writing :)
Pranay
DeleteJust drag dualVO from DataControl and drop on page as form and framework will do all other things (It'll create Data Binding in page def)
Ashish
Got it ...Now my application working fine.. Thank you so much ashish ..
DeleteHappy to help :)
Deleteif i have list like deparetment name ... how i can use it in custom Search
ReplyDeleteHi Tokando
DeleteYou can create a lov in dual vo first for department name and then drop this list in form and use in custom search
Ashish
Hi Ashish,
ReplyDeleteHow is the table getting refreshed when we did not give any partial trigger to the table?
As button has partial submit false then whole page is refreshed and no need of partial trigger
DeleteHi Ashish,
ReplyDeleteI've implemented your sample successfully but I'd need the table with the results (employees) be empty just when page is first loaded.
How can I do it?
BR,
Jose.
Hi Jose
DeleteYou can call executeEmptyRowSet method of viewObject on page load
Ashish
Found it
DeleteIt's just set RefreshCondition="#{!adfFacesContext.initialRender}" to the iterator
https://blogs.oracle.com/shay/entry/preventing_queries_when_page_f
Good to know, Just another way :)
DeleteThanks for your help, Ashish
DeleteYou are welcome jose :)
DeleteSorry Ashish, but I have another problem with your example.
DeleteCould you please check here?
https://community.oracle.com/message/14332993
BR,
Jose.
when i run the page there is no text field available to fill in , only the label for each one is showed
ReplyDeleteHi Kareem
DeleteMake sure that you have set updatable to always in attributes property of viewobject
Ashish
Why did you call attrVo.executeQuery()?
ReplyDeleteThanks in advance
To reset all attributes of dual VO that is used as search form , On Reset action all fields of search form should be empty
DeleteI tried to download the sample app but got a secure connection failed error. Would you please check it out? I did fine until I got to 'Now to get value from Form Field to bean , i have created binding for all 4 fields in bean'. I need guidance on where and when to create the bean. Thanks!
ReplyDeleteCheck this - Download Sample App
DeleteHow do you get the text fields to display when the form loads? the textboxes aren't populating, just labels. I am using JDeveloper 12C.
ReplyDeleteHi Samantha
DeleteSet updatable=Always for dual viewObject's attributes and check again
Ashish
Hi Ashish
ReplyDeleteI am new to ADF, using JDev12c. I dropped DualVo as a form and now creating a bean for the search button. I create a new bean and a method 'searchButton' but I don't see any bindings for the fields like your class file has. Can you point out my mistake?
For now I have created the bindings manually and completed the tutorial for search button. I am using LOV and autosuggest in my 2 search fields. The autosuggest was working before adding the bean for search button but it stopped working after I added the searchButton method. Now it shows 'No results found' for any keyword. Any ideas why?
DeleteI think your issue is resolved
DeleteThanks Ashish
ReplyDeletei have some quite deferent scenario, need your help
the dual VO has five attribute, 1 input text, 3 date, and 2 LOV (select one choice) , and the OR used in the where VC, so user can use any on the bind variables.
the result when i clicked the search button it shows all records.
Q: how to show records based on user inputs, and how to control the VO.executeQuery() ?
thanks