Additionally you use the task flow as a region within the mainHR page.
In the EJB, you add a named query using the @NamedQueries annotation syntax.
-
Close all open tabs and expand the Model project.
-
Double click the Employees.java class to open it in the Source editor.
-
In the Source editor, open the Entity node to visualize the @NamedQuery statement within the @NamedQueries annotation.
-
Add a comma after the closing parenthesis of the NamedQuery statement and hit Enter to add a new line.
-
Add a query to the class that retrieves data about employees having a salary greater than a parameter value. Add the following statement:
@NamedQuery(name = "Employees.findBySal", query = "select o from Employees o where o.salary > :p_sal")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")
})
If required, use the ALT + Enter keystroke combination to import the javax.persistence.NamedQueries library. -
Click the Make icon to compile your project and check that no errors are returned.
-
In the Application Navigator, right-click HRFacadeBean.java and select Edit Session Facade from context.
-
In the Specify Session Facade Options, check the new query you just added getEmployeesFindBySal().
Click OK. Click the Save All icon to save your work.
-
In the Application Navigator, right-click HRFacadeBean.java and select Create Data Control from context.
-
In the Choose EJB Interface, leave the default (local) selection and click OK.
-
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.
-
Your new method is now ready to be used as a data control in your pages.
-
Click the Save All icon to save your work.
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.
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") })
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 |
ADF task flows provide a modular approach for defining control flow in a Fusion web application.
-
Close the Model project. Right-click the ViewController project and select New from context.
-
In the New Gallery, select Web Tier > JSF/Facelets as the Category and ADF Task Flow as the item. Click OK.
-
In the Create Task Flow dialog, enter findBySalFlow.xml. Create as a bounded task flow with page fragments. Click OK.
-
Drag and drop a View component onto the task flow.
-
Drag and drop a second View component onto the task flow.
-
Select the Control Flow Case component and clicking in view1, drop it onto view2. Rename the flow find.
-
Repeat the operation to create a second Control Flow Case from view2 to view1 and rename it back.
-
Double-click view1 to create the page. In the Create ADF Page Fragment the page should be a jsff file type.
Click OK.
A page fragment is a JSF document that renders as content in another JSF page. Read more...
Page fragments are typically used in bounded task flows that can be added to a JSF page as a region -
Open the Data Controls pane, and drop the getEmployeesFindBySal() method onto the page as Parameter --> ADF Parameter Form.
-
In the Edit Form Fields enter Salary > in the Display Label field and click OK to accept other defaults. Notice the parameter p_sal.
-
Select the getEmployeesFindBySal button. Then in the Property Inspector, set the Action property to find from the list and the Text property to Find.
-
From the Component Palette, in the Operations library, select Set Action Listener and drop it onto the Find button.
You use the Set Action Listener to hold the parameter value typed in View1 at a pageFlowScope level.
-
In the Insert Set Action Listener dialog, click the down arrow next to the From field and select Expression Builder.
-
In the Expression Builder, expand ADF Bindings > bindings and select getEmployessFindBySal_p_sal.
Click OK.
-
Back in the Insert Set Action Listener dialog, in the To field, enter #{pageFlowScope.sal}.
Click OK.
-
The Structure pane and the property inspector should now look like the following:
-
Click the findBySalFlow.xml tab to reopen the task flow diagram. In the task flow diagram, double click view2 to create the page.
-
In the Create ADF Page fragment, accept the default values.
Click OK.
-
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.
-
In the Edit Table Columns dialog, select Single Row , Enable Sorting and Enable Filtering. Delete all columns after salary and also delete hiredate.
Click OK.
-
In the Edit Action Binding dialog, in the Value field enter #{pageFlowScope.sal}.
Click OK.
-
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.
-
In the Property Inspector, enter Back as Text and select back for the action.
-
Click the Save All icon to save your work.
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.
A bounded task flow has a single point of entry, a default activity that executes before all other activities in the task flow.
The value is passed to the p_sal parameter before executing the query.
You can render a bounded task flow in a JSF page or page fragment (.jsff) by using an ADF region.
-
Click the mainHR.jsf node in the Application Navigator to reopen the mainHR.jsf page.
-
Right click the Graph tab and select Insert After Show Detail Item > Show Detail Item.
-
In the Property Inspector, change the Text field to Search.
-
In the Application Navigator, expand the Web Content > WEB-INF nodes and drag and drop the findBySalFlow.xml node within the Search pane.
-
Select Create > Region from context.
-
The page region should look like the following:
Click the Save All icon to save your work.
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.
-
Right click within the page and select Run from context.
-
In your Browser window, click the Search tab.
-
Enter a value in the Salary field (for example 8000) and click the Find button.
-
A list of the corresponding employees is returned. Scroll right to verify that no salaries =< 8000 are returned.
-
Click the Back button.
-
Enter a new value in the Salary field (for example 10000) and click the Find button.
-
A more restricted list is now displayed.
-
Close the browser window.