Terje from Norway writes in to ask, "I have a jsp web page showing an ordinary html-table with rows from a view object. One of the columns is postal code. I want to make a simple textfield and a submit button on the page that makes it possible to filter the table to show only rows with a user-entered postal-code. How is this done in JDeveloper 10g?"
As you might expect, doing any kind of filtering of query results in a database application boils down to getting an appropriate WHERE clause added to the SQL SELECT statement being performed to populate your display. I've prepared a SimpleFilteredQueryExample which illustrates how you can approach doing this in JDeveloper 10g when using ADF and JSP.
To run the demo, you'll need the JDeveloper 10g preview release (9.0.5.0 build 1375)
After opening the SimpleFilteredQueryExample.jws workspace, and making sure you have a database connection named scott defined which points to a SCOTT/TIGER account you have in your environment:
- Expand the ViewController project, the Web Content folder, and the WEB-INF folder under that to click on the struts-config.xml file.
-
Select the /employeesDataAction action in the structure pane (under "Action Mappings"), and select "Run" from the right-mouse menu to run this struts action.
Your default browser should appear and you'll see a form showing EMP table records 3 at a time. You can click (Next Set) and (Previous Set) buttons to page back and forth through the records.
If you type in a value like "10" into the "Filter" text box, then click on (Filter), you will filter the data to only show employees in that department. You then can page through the results of only that filtered set, if you want.
To remove the filter, click on the (Filter) button with no value in the text field.
Study the code of the demo.view.EmployeesDataAction so see how the filtering works. The comments in there explain what's going on. I've provided two alternative implementations of the code to do the filtering. One method named setupModelForPageRightHereInTheAction() illustrates how to do the filtering right in the Struts action, although that's not the most encapsulated way to accomplish the job. The alternative method setupModelForPageMoreEncapsulated() shows how you can encapsulate the logic that manipulates the details of your view object components into your ADF view objects and application module components. Then, the Struts action simple invokes custom service methods on the application module's custom service interface (named demo.model.common.MyModule in this example for my demo.model.MyModule application module component).
We also support a more generic Query by Example capability on view objects if your filtering requires allowing the end-user to pick and choose to filter on a user-defined combination of query critieria for the fields. See the JavaDoc for our oracle.jbo.ViewCriteria object, or my BC4J Coding Techniques example for some pointers on using it.
10:55:25 AM
|