Reputation: 1847
How do get this simple task done in ADF -
Based on some parameter I want a row to be retrieved from a view object programmatically. I have no idea how this could be done. IF I am not using ADF my business method would have a query like below and then return whatever details i want in the form on object.
*select * from abcTable where abccolumn = param1;*
param1 is an input from a jsf page. I capture that input and based on that input i need to query another database table (which will be in the form of View object in the ADF) to retrieve additional details and fill up some other components in the jsf page. How do I get this task done. I am trying to get instance of the view object but i do not seem to find any method using which I could retrieve only limited rows i want based on a where clause. The executeQuery method does not return anything (weird case).
Upvotes: 0
Views: 6870
Reputation: 131
Bind that parameter to a variable in your bean. Let's say you want to search the value from and input text:
On page:
<af:inputText id="it8" binding="#{pageFlowScope.<YOURBEAN>.inputSearchBox}"/>
In your bean:
private RichInputText inputSearchBox;
public void setInputSearchBox(RichInputText inputSearchBox) {
this.inputSearchBox= inputSearchBox;
}
public RichInputText getInputSearchBox() {
return inputSearchBox;
}
Make a method in the bean that would do the search:
On page:
<af:commandButton text="search" id="cb6" actionListener="#{pageFlowScope.<YOURBEAN>.search}"/>
In bean:
public void search(ActionEvent actionEvent) {
}
In this method you will need to get the ViewObject from AppModuleImpl:
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc =bindingContext.findDataControl("YOURAPPMODULEDATACONTROL");
AppModuleImpl appM = (AppModuleImpl )dc.getDataProvider();
ViewObjectImpl vo = appM.getYourVO();
Create and apply a view criteria on that viewObject with the text that you entered in the input:
String searchValue = null;
//get the value from the search field
if (inputSearchBox.getValue() != null) {
searchValue = inputSearchBox.getValue().toString();
}
ViewCriteria vc = vo.createViewCriteria();
ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
vcRow.setAttribute("Field you want to search by", searchValue);
vc.addRow(vcRow);
vo.applyViewCriteria(vc);
vo.executeQuery();
Now the ViewObject is filtered by your search value. If you want to go through the result and save some VO values from that line you found you would need to make a row iterator, iterate through it and store the values you need in some variables:
RowSetIterator rsi = vo.getRowSetIterator();
String valueToGet = null;
while (rsi.hasNext()){
Row r = rsi.next();
valueToGet = (String)r.getAttribute("<WHAT ATTRIBUTE YOU WANT TO GET>");
}
Upvotes: 0
Reputation: 3721
The VO has a setWhereClause method that you can use to add/modify a where clause to the query. You can also pre-define a VO with a bind parameter query.
Some more info on the UI side : ADF Query with Parameters and List of Values and ADF Query with Parameters and List of Values - Part II
Upvotes: 0
Reputation: 83
You can filter viewObject programmatically and can get rows- you can filter viewObject using 2 methods 1. where clause 2. filterdRows see- Get Filtered Rows From View Object in Oracle ADF
Upvotes: 1