Skip Headers
Oracle® Application Development Framework Developer's Guide For Forms/4GL Developers
10g (10.1.3.1.0)

Part Number B25947-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7.2 Creating an Entity-Based View Object

Creating an entity-based view object is even easier than creating a read-only view object, since you don't have to type in the SQL statement yourself. An entity-based view object also offers significantly more runtime functionality than its read-only counterpart.

7.2.1 How to Create an Entity-Based View Object

To create an entity-based view object, use the Create View Object wizard. The wizard is available from the New Gallery in the Business Tier > ADF Business Components category. Assume that you want to create a StaffList view object in the devguide.model.queries package to retrieve an updatable list of staff members.

As shown in Figure 7-2, in step 1 on the Name page, provide the view object's name and package. Keep the default setting to manage data with Updatable Access through Entity Objects.

Figure 7-2 Providing a Name and Package for an Updatable View Object

Image of Step 1 of the Create View Object wizard

In step 2 on the Entity Objects page, select the entity object whose data you want to use in the view object. Figure 7-3 shows the result after selecting the User entity object and shuttling it into the Selected list. An entry in this list is known as an entity usage — since it records the entity objects that the view object will be using. It could also be thought of as an entity reference, since the view object references attributes from that entity.

Figure 7-3 Selecting the Entity Objects Whose Data You Want to Include in the View Object

Image of step 2 of the Create View Object wizard

In step 3 on the Attributes page, select the attributes you want to include from the entity usage in the Available list and shuttle them to the Selected list. In Figure 7-4, the UserId, Email, FirstName, and LastName attributes have been selected.

Figure 7-4 Selecting the Entity Attributes Whose Data You Want to Include in the View Object

Image of step 3 of the Create View Object wizard

In step 4 on the Attribute Settings page, you can use the Select Attribute dropdown to switch between the view object attributes in order to change their names or any of their initial settings. For this example, you can accept the defaults.

In step 5 on the SQL Statement page, as shown in Figure 7-5, JDeveloper automatically generates the SELECT statement based on the entity attributes you've selected. You can add a WHERE and ORDER BY clause to the query to filter and order the data as required. Since this StaffList view object should display only the rows in the USERS table that have a value of technician or manager for the USER_ROLE column, you can include an appropriate WHERE clause predicate in the Where field. To order the data by last name and first name, included an appropriate ORDER BY clause in the Order By field. Notice that the Where and Order By field values appear without the WHERE or ORDER BY keyword. The view object adds those keywords at runtime when it executes the query.

Figure 7-5 Adding Custom Where and Order By Clauses to the Generated SQL Statement

Image of step 5 of the Create View Object wizard

Click Finish at this point to create the view object.

7.2.1.1 Creating a View Object Having All Attributes of an Entity Object

When you want to allow the client to work with all of the attributes of an underlying entity object, you can use the Create View Object wizard as described in Section 7.2.1, "How to Create an Entity-Based View Object". After selecting the entity object, simply select all of its attributes on the Attributes page. However, for this frequent operation, there is an even quicker way to perform the same task in the Application Navigator.

To create a new entity-based view object:

  1. Select the desired entity object in the Application Navigator.

  2. Choose New Default View Object... from the context menu.

  3. Provide a package and component name for the new view object in the Create Default View Object dialog, as shown in Figure 7-6.

Figure 7-6 Shortcut to Creating a Default View Object for an Entity Object

Image of Create Default View Object dialog

The new entity-based view object created will be identical to one you could have created with the Create View Object wizard. By default, it will have a single entity usage referencing the entity object you selected in the Application Navigator, and will include all of its attributes. It will initially have neither a WHERE nor ORDER BY clause, and you may want to use the View Object Editor to:

  • Remove unneeded attributes

  • Refine its selection with a WHERE clause

  • Order its results with an ORDER BY clause

  • Customize any of the view object properties

7.2.2 What Happens When You Create an Entity-Based View Object

When you create an entity-based view object, JDeveloper creates the XML component definition file that represents the view object's declarative settings and saves it in the directory that corresponds to the name of its package. In Figure 7-2, the view object was named StaffList in the devguide.model.queries package, so the XML file created will be ./devguide/model/queries/StaffList.xml under the project's source path. This XML file contains the information about the SQL query, the name of the entity usage, and the properties of each attribute. If you're curious to see its contents, you can see the XML file for the view object by selecting the view object in the Application Navigator and looking in the corresponding Sources folder in the Structure Window. Double-clicking on the StaffList.xml node will open the XML in an editor so you can inspect it.


Note:

If your IDE-level Business Components Java generation preferences so indicate, the wizard may also create an optional custom view object class StaffListImpl.java and/or a custom view row class StaffListRowImpl.java class.

7.2.3 Editing an Existing Entity-Based View Object Definition

After you've created an entity-based view object, you can edit any of its settings by using the View Object Editor. Select the Edit menu option on the context menu in the Application Navigator, or double-click on the view object, to launch the view object editor. By opening the different panels of the editor, you can adjust the WHERE and ORDER BY clause of the query, change the attribute names, add named bind variables, add UI controls hints, control Java generation options, and configure other settings.

7.2.4 What You May Need to Know About View Objects

Each view object attribute inherits the properties of the corresponding entity object attribute.

7.2.4.1 View Object Attributes Inherit Properties from Underlying Entity Object Attributes

One interesting aspect of entity-based view objects is that each attribute that relates to an underlying entity object attribute inherits that attributes properties. Figure 7-7 shows the View Object Editor with the UserId attribute selected. You can see that properties like the Java Attribute Type and the Query Column Type are disabled and their values are inherited from the related UserId attribute of the User entity object to which this view object is related. Some properties like the attribute's datatype are inherited and cannot be changed at the view object level.

Other properties like Queryable and Updatable are inherited but can be overridden as long as their overridden settings are more restrictive than the inherited settings. For example, the UserId attribute in the User entity object has an Updatable setting of Always. As shown Figure 7-7, the View Object Editor would allow you to set the corresponding view object attribute to a more restrictive setting like While New or Never. However, if the UserId attribute in the User entity object had instead an Updatable setting of Never, then the editor would not allow the StaffList's related view object attribute to have a less restrictive setting like Always.

Figure 7-7 View Object Attributes Inherit Properties from Underlying Entity Object Attributes

Image of View Object editor