Creating a View Object

You can create default view objects for your entity objects in the Entity Object Wizard, but these view objects are very simple in their definition. The View Object Wizard lets you create view objects that can be tailored for your needs. Use the View Object Wizard if you want to create a view object which uses:

A view object joins, filters, and sorts business data, shaping it for presentation. view objects encapsulate SQL code and metadata that maps columns in a SELECT statement to attributes of one or more entity objects. View objects provide clients with rowsets they can scroll through and update without concern for or knowledge of the underlying entity objects.

To create a view object, you must first have an open business project. If you already have a business project which contains objects, you have two options:

In either case, the View Object Wizard opens:

  1. If the Welcome screen appears, click Next to continue.

  2. Replace the default in the Name field with an view object name that will be meaningful to your client applications. In the Package field you can accept the default package where the object will reside, or you can choose another package by clicking Browse. When you are finished with the Name page, click Next.

    Note: The Extends field lets you extend the functionality of an existing view object without having to modify the source code. See Extending Java and XML for Business Components for details.

  3. In the Entity Objects page, select the entity objects from the Available list that you want to be referenced by the view object. Use the right-arrow to move selected entity objects to the Selected list. You can provide an alternate name for the selected entity objects in the Alias field.

    If you select the Read Only checkbox, attributes from the corresponding entity object cannot be edited from this view object. By default, when you move entity objects to the Selected list, the first entity object is updateable; subsequent entity objects are read-only. You can change the updateability of any entity object in the Selected list by selecting the entity object, then selecting or clearing the Read Only checkbox. The ability of a view object to have multiple updateable entity objects enables one of the key features of Business Components for Java: a single view object can update multiple entity objects.

    If you select the Reference checkbox, attribute values for the entity object are dynamically fetched from the entity cache when a controlling key attribute changes.

    When you are finished with this page, click Next.

  4. In the Attributes page, choose the entity object attributes that you want included in the view object. Click New to create a calculated or transient attribute. When you are finished with this page click Next.

  5. In the Attribute Settings page choose storage and update properties for the view object attributes you select in the Select Attribute dropdown list.

Attribute group:

Query Column group:

  1. In the Query page, you have the opportunity to view and edit the WHERE and ORDERBY clauses of the SQL statement used to query the database. In the OrderBy field, you can click Browse to choose attributes by which to order the query results. The page also offers a convenient Test button where you can test that your SQL is syntactically valid.

    If you want to use bind parameters in any of your SQL clauses, select Use ? style parameters when you want to use the question mark (?) parameter style instead of the colon (:) style. You will need to use the same style in the View Link query definition.

    If you need even more flexibility in specifying your query statement, select the Expert Mode option. The contents of the Query page changes, giving you an editable area where you can edit the entire query, or paste a query from another source. There are no limits on the length or complexity of the query you can enter. Like normal mode, you can browse for OrderBy attributes and test the validity of your SQL code.

    You also have the option of entering your custom SQL query directly into the generated XML file. For more information see Pasting a Custom Query in a View Object XML File.

    Note: If you make changes to the query in Expert Mode, then clear the checkbox to return to normal mode, your query edits will be discarded.

    When you are finished with this page, click Next. If you click Next in Expert Mode, the Attribute Mappings page opens. If you click Next in normal mode the Java page opens.

  1. The Attribute Mappings page gives you the opportunity to re-map query columns to object attributes if you deleted, added, or switched positions of columns in your custom SQL statement. To change the mapping, click an attribute in the right side of the grid. A dropdown list lets you select another attribute to map to the query column. You can also remove the mapping for a particular query column. Query columns that are not mapped cannot be updated. When you are finished with this page, click Next.

  2. The Java page provides options that let you generate classes (that is, *Impl classes) for the view object and the View Rows. After the framework creates these classes, you can edit them to customize the view object's behavior:

    When you are finished with this page click Next.

If you selected the Generate Java file option, the Business Component for Java framework generates a .java and .xml file for your view object and displays their names in the Navigation pane. If you did not select the Generate Java file option, the framework generates only an XML file.