Requirement: Sometimes we need to filter the ViewObject Data and the result we want to use only inside the Managed Bean or any other Java classes. Thus, in such cases, we can make use of the getFilteredRows method.
Solution: For solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application.
Create a Business Components from Tables for the Employees table of the HR schema of the Oracle Database 11g XE Edition.
Create or expose the AppModuleImpl.java class.
Step 2: Create a demo.jspx page inside the ViewController project.
Drag and drop an af:inputText and set label=”Enter Department ID”. and binding=”#{pageFlowScope.MyBean.departmentIdBinding}”
Drag and drop af:button and set text=”Search” and actionListener=”#{pageFlowScope.MyBean.searchActionListener}”
Thus, the complete code for the demo.jspx is shown below:
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="" version="2.1" xmlns:f="" xmlns:af=""> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="demo.jspx" id="d1"> <af:form id="f1"> <af:inputText label="Enter Department ID" id="it1" binding="#{pageFlowScope.MyBean.departmentIdBinding}"/> <af:button text="Search" id="b1" actionListener="#{pageFlowScope.MyBean.searchActionListener}"/> </af:form> </af:document> </f:view> </jsp:root>
And the complete code for MyBean.java class is as shown below:
package susantotech.com; import javax.el.ELContext; import javax.el.ExpressionFactory; import javax.el.ValueExpression; import javax.faces.application.Application; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import model.AppModuleImpl; import oracle.adf.view.rich.component.rich.input.RichInputText; import oracle.jbo.Row; import oracle.jbo.ViewObject; public class MyBean { private RichInputText departmentIdBinding; public MyBean() { } public void setDepartmentIdBinding(RichInputText departmentIdBinding) { this.departmentIdBinding = departmentIdBinding; } public RichInputText getDepartmentIdBinding() { return departmentIdBinding; } public void searchActionListener(ActionEvent actionEvent) { int departmentIdvalue = 0; if (null != departmentIdBinding.getValue()) { departmentIdvalue = Integer.parseInt((String) departmentIdBinding.getValue()); } AppModuleImpl appModule = (AppModuleImpl) resolvElDC("AppModuleDataControl"); ViewObject employeesVo = appModule.getEmployeesVO1(); Row filteredRows[] = employeesVo.getFilteredRows("DepartmentId", departmentIdvalue); System.out.println("Filtered Employees for Department " + departmentIdvalue + " are"); for (Row r : filteredRows) { System.out.println(r.getAttribute("FirstName") + " " + r.getAttribute("LastName")); } } public Object resolvElDC(String data) { FacesContext fc = FacesContext.getCurrentInstance(); Application app = fc.getApplication(); ExpressionFactory elFactory = app.getExpressionFactory(); ELContext elContext = fc.getELContext(); ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{data." + data + ".dataProvider}", Object.class); return valueExp.getValue(elContext); } }
Step 3: Now, create a page definition file for the demo.jspx page.
Create an Iterator for the EmployeesVO1 as shown below.
Save all and run the application. Thus, the ran application is shown below:
Enter the Department ID value as 60. Click on the Search button.
Now, let me go to the console of the JDeveloper and we can see the output as shown below:
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
732 total views, 2 views today