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 3.0 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.
show more or less

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 class to open it in the Source editor.

  3. What makes these objects different from other Java files are the annotations that identify them as EJB entities. Show more or lessRead more...
    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, 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. Show more or less Read more...

    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. Show more or lessRead more...

    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. Click the Make icon to compile your project and check that no errors are returned.

    Make icon
  10. In the Application Navigator, right-click and select Edit Session Facade from context.

    Context menu
  11. In the Specify Session Facade Options, check the new query you just added getEmployeesFindBySal().

    Specify Session Facade Options dialog

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

  12. In the Application Navigator, right-click and select Create Data Control from context.

    Context menu to create data control
  13. In the Choose EJB Interface, leave the default (local) selection and click OK.

    Choose EJB Interface
  14. In the Data Control Registry, expand the HRFacadeLocal node. Open the new method you just created and click the Employees node. Notice the existing attributes corresponding to the EJB JPA definition.

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

  16. 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. Close the Model project. Right-click the ViewController project and select New from context.

    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. Create as a bounded task flow with page fragments. Click OK.

    Create Task Flow dialog
  4. There are two types of ADF task flow: Show more or lessRead more...

    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 and drop a View component onto the task flow.

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

    Task flow diagram with views
  7. Notice the circle around view1. It represents the entry point within the task flow. Show more or lessRead more...

    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 clicking in view1, drop it onto 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 the page. In the Create ADF Page Fragment the page should be a jsff file type.

    Create ADF Page Fragment dialog

    Click OK.

    A page fragment is a JSF document that renders as content in another JSF page. Show more or lessRead more...

    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 drop the getEmployeesFindBySal() method onto the page as Parameter --> ADF Parameter Form.

    Dropping data control on a page
  12. In the Edit Form Fields enter Salary > in the Display Label field and click OK to accept other defaults. Notice the parameter p_sal.

    Edit Form Fields dialog
  13. Select the getEmployeesFindBySal button. Then in the Property Inspector, set the Action property to find from the list and the Text property to Find.

    Property Inspector
  14. From the Component Palette, in the Operations library, select Set Action Listener and drop it onto the Find button.

    Dropping a Set Action Listener on a button

    You use the Set Action Listener to hold the parameter value typed in View1 at a pageFlowScope level.

  15. In the Insert Set Action Listener dialog, click the down arrow next to the From field and select Expression Builder.

    Insert Set Action Listener dialog
  16. In the Expression Builder, expand ADF Bindings > bindings and select getEmployessFindBySal_p_sal.

    The Expression Builder dialog

    Click OK.

  17. Back in the Insert Set Action Listener dialog, in the To field, enter #{pageFlowScope.sal}.

    Insert Set Action Listener dialog

    Click OK.

  18. The Structure pane and the property inspector should now look like the following:

    Structure pane
  19. Click the findBySalFlow.xml tab to reopen the task flow diagram. In the task flow diagram, double click view2 to create the page.

    Page flow diagram
  20. In the Create ADF Page fragment, accept the default values.

    Create ADF Page fragment dialog

    Click OK.

  21. In the Data Controls pane, expand the getEmployeesFindBySal() method then drag and drop Employees onto the page. Select Table --> ADF Read-only Table from context.

    Dropping data control onto the page
  22. In the Edit Table Columns dialog, select Single Row , Enable Sorting and Enable Filtering. Delete all columns after salary and also delete hiredate.

    Edit Table Columns dialog

    Click OK.

  23. In the Edit Action Binding dialog, in the Value field enter #{pageFlowScope.sal}.

    Edit Action Binding dialog

    Click OK.

  24. The pageFlowScope.sal value indicates which salary parameter value to use. Show more or lessRead more...

    The value is passed to the p_sal parameter before executing the query.
  25. From the Component Palette, select the Button component in the ADF Faces > General Controls library and drop it above the af:table node in the Structure pane.

    Component Palette
  26. In the Property Inspector, enter Back as Text and select back for the action.

    Property Inspector
  27. 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. Click the mainHR.jsf node in the Application Navigator to reopen the mainHR.jsf page.

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

    Context menu
  3. In the Property Inspector, change the Text field to Search.

    Property Inspector
  4. In the Application Navigator, expand the Web Content > WEB-INF nodes 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 Salary 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.

    alt text
  5. Click the Back button.

    Navigating Back to previous page
  6. Enter a new value in the Salary 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 © 2011, Oracle and/or its affiliates. All rights reserved.