Articles
Application Development Framework
Chapter 2 - The "Must-Have" Requirements: A Basic Search ApplicationPublished May 2009
Click here to see "Taking an Oracle ADF Application from Design to Reality" description and Table of Contents
In this chapter we will build the MUST-have requirements: initially we only need the search fields and a basic search screen. Once we know our table structures we now know what to start building in our Oracle JDeveloper 11g ADF application. We start with an application based on the "Fusion Web Application Template" that gives us the Model and ViewController projects preconfigured with the Oracle ADF Business Component and Oracle ADF Faces RC libraries necessary.
Creating View ObjectsNext with the Model project selected, we run the "Business Components from Tables" wizard to create a read-only View Objects based on the parcels table, and an Application Module to serve the View Object to the ViewController project later.
To ensure that we have everything working OK, we run the Business Component Browser on the AppModule. We can then see the following results from the ParcelsView View Object: Now that we've created the View Object, our next requirement is to provide the search capabilities. Oracle ADF Business Components supports a number of mechanisms to allow the user to search, one of which is built in by default and can be seen through the Business Component Browser by clicking on the View Criteria button: In our case while this mechanism is useful, we do know that we have the upcoming requirement to convert the string search fields to uppercase to match our database data, and remove the hyphens from the waybill number if supplied. An alternative mechanism is to create bind variables for the View Object. We modify our View Object query to look like the following:
We note the addition of the bind variables under the same named option. At this stage, we're not worried about the requirement of converting the search fields to uppercase or fixing the waybill number, so we'll leave the rest of the query alone. We're just being mindful that even though we've placed a requirement in the "should have" category, this doesn't mean that we should totally ignore it. We can make our future job easier by using features that we'll harness later. Again we test our View Object through the Business Component Browser to ensure that we haven't made a mistake. This time when we run the View Object, a dialog box will appear asking us to enter values for each bind variable. Once we are done, assuming that we've entered valid search values, a record will be returned: To do this we first need to generate our ViewObjectImpl class for the ParcelsView by opening the View Object editor Java node and then selecting the Edit button and the Generate View Object Class option:
public class ParcelsViewImpl extends ViewObjectImpl {
@Override
protected void executeQueryForCollection(Object queryCollection,
Object[] bindParams, int noUserParams) {
super.executeQueryForCollection(queryCollection, bindParams, noUserParams);
}
... the rest of the class ...
We can now write a method to extract the bind parameters and check how many we've received:
private void enforceQueryCriteria() {
Object[] attrValues = getNamedWhereClauseParams().getAttributeValues();
int i = 0;
boolean missingParam = false;
while (i < attrValues.length && !missingParam) {
if (attrValues[i] == null || (attrValues[i] instanceof String && attrValues[i].equals("")))
missingParam = true;
i++;
}
if (missingParam)
throw new JboException("You must enter all the enquiry criteria");
}
Ideally the JboException message should be sourced from a message bundle, but we'll keep this example brief.
Once we have this method we return to our executeQueryForCollection() method and call our enforceQueryCriteria() method before hand to enforce the requirement:
public class ParcelsViewImpl extends ViewObjectImpl {
@Override
protected void executeQueryForCollection(Object queryCollection,
Object[] bindParams, int noUserParams) {
enforceQueryCriteria();
super.executeQueryForCollection(queryCollection, bindParams, noUserParams);
}
... the rest of the class ...
In testing this solution in the Business Components Browser we hit an error on opening the ParcelsView:
public class ParcelsViewImpl extends ViewObjectImpl {
boolean firstQuery = true;
@Override
protected void executeQueryForCollection(Object queryCollection, Object[] bindParams, int noUserParams) {
if (firstQuery)
firstQuery = false;
else
enforceQueryCriteria();
super.executeQueryForCollection(queryCollection, bindParams, noUserParams);
}
... the rest of the class ...
Building the Search PageGiven that we have the Oracle ADF Business Components working in the manner we require, it's time to create our first Web page. Given an empty page called SearchPage.jspx, we can use the Data Control Palette to drag our View Object onto the page: SummaryIn this chapter we have learned how to build a basic search screen to satisfy the
MUST Have requirements of our application.
Chapter 3 covers adding some additional features to the application, including logging of the user's IP address if they accept our terms and conditions.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||