Web applications usually have more than one page in them. In this part of the tutorial you add another page - a Search page - to your application and use the ADF Task Flow Diagrammer to define the navigation rules between the two pages. You then use features of the ADF Faces Framework to add extra functionality to the pages. Finally you create a reusable page fragment and add it to the DeptEmpPage page.
This is the Search page for the application.
-
In the Application Navigator locate the adfc-config file under the Page Flows node in the ViewController project. Double-click it to open it in the editor. This is where you are going to define the application's navigation.
-
Drag the DeptEmpPage.jsf file from the Application Navigator into the empty adfc-config diagram.
-
From the Component Palette drag and drop a View component into the adf-config diagram, and rename it query. This represents the new JSF page that you are about to create.
-
From the Component Palette select Control Flow Case and then click on the DeptEmpPage and drag a line to the query page.
Name this line goQuery.
-
From the Component Palette choose another Control Flow Case and then create an opposite flow from the query page to the DeptEmpPage. Name this flow back.
-
Double-click the query view in the diagram to create the new page. In the Create JSF Page dialog accept the default Facelets radio button, and with the Quick Start Layout radio button selected, click Browse.
-
In the Component Gallery, retain the default One Column category, type and layout, but check the Apply Themes checkbox in the Options pane.
Click OK and OK again to create the page.
-
To add the employees search functionality to the page, open the Data Controls accordion, and locate EmpDetails1. (If you do not see it click the Refresh button).
-
Expand the EmpDetails1 data control and expand the Named Criteria node below it. Select All Queriable Attributes and drag it into the new query.jsf page. Create it as a Query > ADF Query Panel.
-
In the Data Controls accordion select the EmpDetails1 data control and drag it into the center area of the page below the query component. Create it as a Form > ADF Form.
In the Edit Forms Details, check both the Include Navigation Controls and the Include Submit Button checkboxes. Click OK.
-
With the panelFormLayout still selected, use the Property Inspector to set the Rows property to 5.
-
In the Structure window locate the Submit button, right-click it and choose Insert after af:command:Button - Submit > Button.
-
In the Property Inspector change the Text of the new button to Back and for the Action property select back from the drop down list. This causes the button to perform the navigation you defined in the page flow diagram.
-
Next you add transaction operations to the page to allow you to commit and rollback changes. In the Data Controls Palette expand the application module level Operations node to locate the commit and rollback operations. Drag the Commit operation into the Structure window before the First Button. When prompted for a drop target choose ADF Button.
-
Repeat the same steps for the Rollback operation.
-
In the Property Inspector, for the Rollback and for the Commit buttons, reset the Disabled property to default to make both buttons always selectable.
-
Double-click the Query.jsf tab to maximise the page in the Design Editor. Your page should look as follows:
-
Click the DeptEmpPage.jsf tab to switch back to the page. A quick way to navigate to this or any other file is by using the global find box at the top right of JDeveloper and typing the file name there.
Then just click the file name to open it in the editor.
-
In the page design, expand the Departments accordion. From the Component Palette, choose a Button component and drag it into the Departments accordion between the First and Previous buttons. Alternatively you can right-click the First button and choose insert after > button to add the new button.
-
Using the Property Inspector change the Text of the button to Query and for the Action property type goQuery or select it from the drop down list if available. This causes the button to perform the navigation you defined in the page flow diagram.
-
Click the Save All icon on the JDeveloper menu bar to save your work, and then right-click the DeptEmpPage.jsf page and choose Run.
-
When the page displays in your browser click the Query button to navigate to the new page. In the Search page click Advanced to display detailed search criteria.
-
In the FirstName field accept the default Starts with, and type the letter G.
Press Search.The form below displays the record for Guy Himuro. -
Experiment with the form, saving your search criteria, creating more complex queries and updating data for employees. Note how this form displays a view of the data that matches the definition in the view object you created - including information for Department name as well as a list of values for the Job id and the employee's annual salary.
You can also make changes to the data and commit and rollback your transactions as needed.
When you are finished close the browser window.
In the next steps you become acquainted with some of the features of the ADF Faces Framework. You enhance your pages with additional Ajax functionality leveraging the declarative development features offered by ADF Faces components.
The application requirements mean that you need to add an automatic update to the AnnualSalary field whenever the Salary field is updated. You don't want the whole page to refresh when this happens, so you use partial page refresh to just refresh the fields that have changed.
-
Open the query.jsf file in the Design Editor, if it is not already open. Select the Salary field. In the Property Inspector set the value of the Id property to sal.
-
Still in the Property Inspector expand the Behavior node and set the AutoSubmit property to True.
-
In the Structure window locate the AnnualSalary field. (Another option to get to this field is to double-click the query.jsf tab to maximize the window and then locate the field in the Design Editor).
Locate the PartialTriggers property under the Behavior section and click the arrow to its right to choose Edit. -
In the Edit Property dialog locate the Salary field and shuttle it to the right using the blue arrow. Click OK.
-
Click the Save All icon on the JDeveloper menu bar to save your work, and run DeptEmpPage.jsf.
-
When the page displays, click the Query button in the Departments panel.
-
In the Search page search for employees whose first name begins with A%.
Note the salary and annual salary values.
-
Update the Salary field and then tab out of it. Notice the immediate change to the AnnualSalary field once you leave the Salary field. However this is the only field that is refreshed (not the whole page).
-
Close the browser.
-
In the query page, select the JobId field. -
In the Component Palette expand the Operations node, and locate Auto Suggest Behavior in the Behavior section. Drag and drop the Auto Suggest Behavior operation onto the JobId field.
-
In the Insert Auto Suggest Behavior dialog box type #{bindings.JobId.suggestedItems}. Click OK.
-
Save your work and then run the query page.
-
Type 121 in the EmployeeId field, and click the Search button. In the record for Adam Fripp update the JobId field by typing 's' in it. A number of jobs beginning with 's' are suggested.
-
Add 'a' after the 's' and see the list of suggestions modified accordingly.
-
Choose Sales Representative from the three remaining options, to populate the field.
-
Close the browser without saving the change.
In this step you add a drop down menu to a page and use a couple of ADF Faces operation components to add Javascript-based operations to the page - to export table data into an Excel spreadsheet and to create a printable page.
-
In the DeptEmpPage.jsf file click inside the menus facet in the panel collection surrounding the Employees table. Right-click and from the context menu choose Insert Inside Facet menus > Menu.
In the Property Inspector set the Text property to My Options.
-
In the Property Inspector expand the Behavior node and set the Detachable property to true.
-
In the Structure window right-click the menu component and choose Insert inside af:menu - My Options > Menu Item.
-
In the Property Inspector set the Text property of the new menu item to Export to Excel.
-
With the new Export to Excel menu item still selected in the Structure window, expand the Listeners section of the Operations node of the the ADF Faces components in the Component Palette.
Locate the Export Collection Action Listener component and drag it onto the Export to Excel menu option in the Structure window. -
In the Insert Export Collection Action Listener dialog click the down arrow next to ExportedId field and choose Edit.
-
In the Edit Property dialog navigate through the page structure to locate the table - t1 component and select it. Click OK.
-
From the Type drop down list select excelHTML and click OK.
-
Add another menu option to the menu. In the Structure window right-click the Export to Excel menu component and from the context menu choose Insert After af:commandMenuItem - Export to Excel > Menu Item.
-
Set the Text property of this new menu option to Printable Page.
-
In the Behavior section under the Operations node of the Component Palette select the Show Printable Page Behavior operation to add it to the new menu item. Drag and drop it onto the new menu option you created.
-
Click the Save All icon on the JDeveloper menu bar to save your work, and then choose Run.
-
When the page displays click the new menu and detach it.
-
Then invoke each one of the menu options you created, for example Export to Excel.
You may need to accept the download of the file in the browser window to be able to access the Excel file.
-
Try the Printable Page menu option.
The page is ready for printing.
Close the browser window.
-
Click the query.jsf tab to return to the Query page, opening the Structure pane. In the Data Controls accordion expand the EmpDetails1 node and then the Operations node below it. Select the CreateInsert operation.
-
Drag the CreateInsert operation in the Structure pane onto the panelGroupLayout in the footer facet of the employees form. Create it as an ADF Button.
-
In the Property Inspector set the Id property for the button to CreateInsert.
-
Still in the Property Inspector expand the Behavior node and in the PartialTriggers property choose Edit from the dropdown list.
-
In the Edit window scroll through the page's components until you find the CreateInsert button. Shuttle it into the Selected pane.
Click OK. This action defines the CreateInsert component as the trigger that will cause the table to refresh.
-
In the same way add a Delete operation by dropping the Delete operation from EmpDetails1 onto the panelGroupLayout in the page footer. As before, create it as an ADF button.
-
The two buttons display at the bottom of the query page.
-
Save your work and then run the Query page.
-
When the page displays type F% in the LastName field and click the Search button. The first F% employee record displays.
-
Click the CreateInsert button. The page refreshes and the fields are cleared down (except for the HireDate field, which you set to default to the current date) so that a new record can be inserted.
-
In the Application Navigator locate the demo.model package and right-click it to choose New View Object....
-
In the Create View Object wizard set the Name property to EmpByEmail and choose the SQL Query radio button as the data source. Click Next.
-
In Step 2 of the Create View Object wizard type the following query:
select first_name,last_name from employees where email=:p_emailThe ':' before p_email means that it is a variable that will be passed to the query.
Click the Test and Explain button to verify your query.
Click Close and then click Next.
-
In Step 3 of the Create View Object wizard, click the New button to define a new bind variable. Set the Name property to p_email.
Click the Control Hints tab and set the Label Text to Email.
-
Click Next a few more times to accept all the defaults, until you get to step 8 of the wizard.
Here check the Add to Application Module check box to include your new view in the data model.
Click the Finish button. -
Save your work and then run the Business Component Browser to test the new view. Double-click the new EmpByEmail1 view and when prompted to insert a value for the variable enter SKING and press OK to get the results for this email address.
Running the Business Component Tester. Read more... Right click the AppModule node in the Application Navigator and select Run from context.
-
To try another value click the Edit Bind Variables button.
Close the Business Component Browser.
-
First create a new task flow specifically for this page.
In the Application Navigator right-click the ViewController project and choose New... -
In the Web Tier > JSF/Facelets category choose ADF Task Flow.
Click OK.
-
In the Create Task Flow dialog set the File Name property to search-email-flow.xml.
Verify that the Create As Bounded Task Flow and Create with Page Fragments checkboxes are both checked.Click OK.
-
In the Design Editor drag a View component from the Component Palette onto the empty diagram and name it searchEmail. You only use a single page in this flow, but you can have bounded task flows with multiple pages and still include them in other JSF pages.
-
Double-click the new searchEmail view component to create the page fragment for it.
Accept all the defaults in the dialog that displays and make sure the file name is searchEmail.jsff. This creates the page as a page fragment that can be included in other JSF pages. Click OK. -
An empty page displays in the Design Editor. Expand the Data Controls accordion and, if necessary, click the Refresh button to ensure that the new EmpByEmail data control appears in the list.
-
Expand the new EmpByEmail1 view and the Operations node beneath it. Select the ExecuteWithParams operation. You are going to use this operation to execute the query for this view passing it the necessary parameter.
-
Drag the ExecuteWithParams operation to your new page, and create it as an ADF Parameter Form.... -
In the Edit Form Fields dialog change the display label for the p_email value from default to Email. Click OK.
-
In the Design Editor for the page, click the ExecuteWithParams button and use the Property Inspector to change the Text property to Find Details.
-
From the Data Controls accordion, drag the EmpByEmail1 view onto the page beneath the button. Create it as a Form > ADF Read-only Form....
-
Accept the defaults presented in the Edit Form Fields dialog and click OK. Save your work.
The page should look like this:
-
The new bounded task flow now contains a page fragment; next you include the complete bounded task flow inside another JSF page.
In the Application Navigator locate the DeptEmpPage.jsf file and open it in the Design Editor, if it is not already open. From the Component Palette Layout section drag and drop a Separator component into the left accordion in the DeptEmpPage.jsf page beneath the Departments form. -
Add the new flow you created as a region to the existing page.
From the Application Navigator drag and drop the search-email-flow.xml file into the left accordion in the DeptEmpPage.jsf page beneath the new separator. Create it as a Region. -
Your page should now look like the screenshot below.
-
Save your work and then run the updated DeptEmpPage.jsf page.
When the page displays in your browser test the new functionality by entering an email value in the Email field and pressing the Find Details button. -
The employee name information is returned.
- Build the business services that supply the data to the application
- Create a data-bound JSF page
- Enhance the page by adding more complex operations
- Add a second JSF page to the application and create a page flow diagram to define the navigation between the pages
- Create a reusable page fragment containing a business service based on parameters
- "Developing Applications Using Web Page Tools" in User's Guide for Oracle JDeveloper
- Web User Interface Developer's Guide for Oracle ADF