Part 3: Adding and Exposing a New Method to the UI
In this section you add a new method to the entity bean using the EJB annotation technique. You then expose the new method to the facade and use it as a data control for pages in a bounded task flow.

Additionally you use the task flow as a region within the mainHR page.

Step 1: Add a New Method to the Entity and Expose it

In the EJB, you add a named query using the @NamedQueries annotation syntax.
  1. Close all open tabs and expand the Model project.

    Model project in the Application Navigator
  2. Double click the Employees.java class to open it in the Source editor.

    Opened Employees.java
  3. What makes these objects different from other Java files are the annotations that identify them as EJB entities. A key feature of EJB 3.0 and JPA is the ability to create entities that contain object-relational mappings by using metadata annotations rather than deployment descriptors as in earlier versions.

  4. In the Source editor, expand (or open) the Entity node to visualize the @NamedQuery statement within the @NamedQueries annotation.

    ")Java code
  5. Named queries enable you to define queries at design time and then use them at run time. Creating the FacadeBean created one NamedQuery metadata statement in the Employee entity. This query retrieves all rows from the Employees table:
    @NamedQueries({ @NamedQuery(name = "Employees.findAll", query = "select o from Employees o") })

  6. Add a comma after the closing parenthesis of the NamedQuery statement and hit Enter to add a new line.

  7. Add a query to the class that retrieves data about employees having a salary greater than a parameter value. Add the following statement:

    So that the code looks like the following:

    @NamedQueries( {
    @NamedQuery(name = "Employees.findAll", query = "select o from Employees o") ,
    @NamedQuery(name = "Employees.findBySal", query = "select o from Employees o where o.salary > :p_sal")
    })


    Java code

    If required, use the ALT + Enter keystroke combination to import the javax.persistence.NamedQueries library.

  8. Any symbol in Java code beginning with @ is known as an annotation. The use of annotations allows you to add metadata to your objects. Examples of annotations follow:
    Annotation Description
    @Entity Identifies the file as an EJB 3.0 entity
    @NamedQuery A query that can be used at run time to retrieve data
    @Table Specifies the primary table for the entity
    @Id Can define which property is the identifier for the entity
    @Column Specifies a mapped column for a persistent property or field
    @ManyToOne Specifies a type of foreign key relationship between tables
    @JoinColumn Specifies the join column and referenced column for a foreign key relationship
  9. Save your work and click the Make icon to compile your project and check that no errors are returned.

    The Messages > Log window will show the results.

    Make icon
  10. In the Applications Navigator, right-click HRFacadeBean.java and select Edit Session Facade from the context menu.

    Context menu
  11. In the Specify Session Facade Options, check the new query you just added getEmployeesFindBySal() and Click OK.
    This exposes the newly added, named query to be available as a data control.

    Specify Session Facade Options dialog
  12. Click the Save All Save All button icon to save your work.

  13. Double click the DataControl.dcx and in the Data Control Registry, expand the HRFacadeBean node. Click the employeesFindBySal node and notice the existing attributes corresponding to the EJB JPA definition.

    Data Control registry
  14. Your new method is now ready to be used as a data control in your pages.

  15. Click the Save All Save All button icon to save your work.

Step 2: Build a Bounded Task Flow with Two JSF Pages

ADF task flows provide a modular approach for defining control flow in a Fusion web application.

  1. In the Applications window, collapse the Model project.. Right-click the ViewController project and select New > From Gallery.

    Context menu
  2. In the New Gallery, select Web Tier > JSF/Facelets as the Category and ADF Task Flow as the item. Click OK.

    New Gallery
  3. In the Create Task Flow dialog, enter findBySalFlow.xml. Also, select the Create as Bounded Task Flow and Create with Page Fragments checkboxes. Click OK.

    Create Task Flow dialog
  4. There are two types of ADF task flows:

    Unbounded task flow
    : A set of activities, control flow rules, and managed beans that interact to allow a user to complete a task. The unbounded task flow consists of all activities and control flows in an application, that are not included within a bounded task flow.

    Bounded task flow: A specialized form of task flow that, in contrast to the unbounded task flow, has a single entry point (an entry point is a view activity that can be directly requested by a browser) and zero or more exit points. It contains its own set of private control flow rules, activities, and managed beans. A bounded task flow allows reuse, parameters, transaction management, reentry, and can render within an ADF region in a JSF page.

    Create with Page Fragments: Clear this checkbox if you want the view activities that you add to the task flow to reference JSF pages that render in the main browser window as the root page. Leave the Create with Page Fragments checkbox checked if you want the view activities that you add to the task flow to reference page fragments files (.jsff) that the task flow displays in an ADF region at runtime.

  5. Drag a View component from the Components palette onto the task flow.

    Task flow diagram
  6. Drag a second View component onto the task flow.

    Task flow diagram with views
  7. Notice the circle around view1. It represents the entry point for the task flow.

    A bounded task flow has a single point of entry, a default activity that executes before all other activities in the task flow.

  8. Select the Control Flow Case component and click once in view1 to select the starting activity for the control flow case,the click in view2. Rename the flow find.

    Task flow diagram with control flow case
  9. Repeat the operation to create a second Control Flow Case from view2 to view1 and rename it back.

    Task flow diagram with control flow case
  10. Double-click view1 to create a page that will be associated with the view activity. In the Create ADF Page Fragment dialog,make sure that the Document Type is Facelets and the Page Layout is Create Blank Page.
    Click OK to create the page.

    Create ADF Page Fragment dialog

    A page fragment is a JSF document that is rendered as content within another JSF page. Page fragments are typically used in bounded task flows that can be added to a JSF page as a region.

  11. Open the Data Controls pane and expand employeesFindBySal. You may need to click the refresh button to see the new collection.
    Expand the Operations node and drag ExecuteWithParameters to the page and add it as an ADF Parameter Form.

    Dropping data control on a page
  12. In the Create Form dialog, enter Salary in the Display Label field and click OK to accept other defaults.

    Edit Form Fields dialog g
  13. Select the ExecuteWithParameters button and in the Properties window, set the Action property to find from the list and type Find as the Text.

    Property Inspector
  14. Save your work.

  15. Click the findBySalFlow.xml tab to reopen the task flow diagram. In the task flow diagram, double click view2 to create a page that is associated with the view2 view activity.

    Page flow diagram
  16. In the Create ADF Page Fragment, click OK to accept the default values.

    Create ADF Page fragment dialog
  17. From the Data Controls palette, drag employeesFindBySal onto the page and select Table/List View > ADF Table.

    Dropping data control onto the page
  18. In the Create Table dialog, select the Single Row, Enable Sorting, Enable Filtering, and Read-Only options Delete all columns after salary and also delete hiredate.
    Click OK to create the table.

    Edit Table Columns dialog
  19. From the Components palette, select the Button component in the ADF Faces > General Controls library and drop it above the af:table node in the Structure window.

    Component Palette
  20. In the Properties window, enter Back as Text and select back for the Action.

    Property Inspector
  21. Click the Save All Save All button icon to save your work.

Step 3: Use the Task Flow as a Region in the mainHR page

You can render a bounded task flow in a JSF page or page fragment (.jsff) by using an ADF region.

  1. Double-click mainHR.jsf in the Applications window to reopen the mainHR.jsf page.

    Context menu

  2. Right click the Emp tab and select Insert After Show Detail Item > Show Detail Item.

    Context menu
  3. In the Properties window, change the Text field to Search.

    Property Inspector Property Inspector
  4. In the Applications window, expand Web Content > Page Flows and drag and drop the findBySalFlow.xml node within the Search pane.

    Dropping a page flow onto a page
  5. Select Create > Region from context.

    Context menu for task flow
  6. The page region should look like the following:

    The page design
  7. A primary reason for executing a bounded task flow as an ADF region is reuse. Show more or lessRead more...

    You can isolate specific pieces of application functionality in a bounded task flow and an ADF region in order to reuse it throughout the application.

    You can extract, configure, and package application functionality within a bounded task flow so that it can be added to other pages using an ADF region. ADF regions can be reused wherever needed, which means they are not dependent on a parent page.
  8. Click the Save All Save All button icon to save your work.

Step 4: Run the mainHr Page
  1. Right click within the page and select Run from context.

    Context menu
  2. In your Browser window, click the Search tab.

    The Running page
  3. Enter a value in the getEmployeesFindBySal_p_sal field (for example 8000) and click the Find button.

    Launching a Search
  4. A list of the corresponding employees is returned. Scroll right to verify that no salaries =< 8000 are returned. Sort on the salary field to make it easy to confirm..

    alt text


    alt text
  5. Click the Back button.

    Navigating Back to previous page
  6. Enter a new value in the getEmployeesFindBySal_p_sal field (for example 10000) and click the Find button.

    Launching a new search
  7. A more restricted list is now displayed.

    Search result
  8. Close the browser window.

Bookmark Print Expand all | Hide all
Back to top
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.