C H A P T E R 9 |
Tutorial--Section 2.3 Create Customer Page |
This chapter describes how to create a page in the Sun ONE Application Framework that displays data from a model that accesses a relational database.
You will now create the second page of the application. However, this page will be bound to a model. This binding process automatically creates display fields on the page that display the data that is stored in the model's fields.
2. Click the Add Page button on the Sun ONE Application Framework toolbar.
The Select View Type panel displays.
3. Enter CustomerPage in the Name field (to replace <default>).
4. Select Basic ViewBean to create a ViewBean type Page component.
The Associate JSP panel displays.
6. Click the Use formatting to beautify fields on JSP check box to apply some basic formatting.
The Model Associations panel displays.
8. Expand Current Application Components to expose jatotutorial -> main.
The Bind Display Fields panel displays.
You only need to add three fields.
a. Select the CUSTOMER_TBL_CUSTOMER_NUM field.
Accept the Static text default.
The CUSTOMER_TBL_CUSTOMER_NUM field is added to the Bound fields list box.
13. Add the second and third fields simultaneously.
a. Select the CUSTOMER_TBL_EMAIL and CUSTOMER_TBL_NAME fields (hold down the Ctrl key to select multiple non-sequential fields).
The CUSTOMER_TBL_EMAIL and CUSTOMER_TBL_NAME fields are added to the Bound fields list box.
You have created the ViewBean.
15. Double-click CustomerPage.
The code displays in the right-hand panel.
Expand all the subnodes of the CustomerPage to see the JSP Page, Visual Components, and Non-Visual Components that were automatically generated by the wizard.
1. Add a button to the CustomerPage.
The following table contains the specifications for adding a button to the CustomerPage. Use the Component Palette to add the button, just like you added the fields for the Login Page.
2. If the Component Palette is not visible, select menu option:
View -> Sun ONE Application Framework -> Component Palette.
The table shown below lists the specifications for adding a button to the CustomerPage. The left column shows the button type, the middle column shows the name, and the right column shows the initial value.
3. Enable the button to update the customer record.
a. Select the update button field.
b. In the property sheet of the button, click the value area of the RequestHandler property.
The Command Descriptor editor launches.
4. Select Create new shared instance.
5. Select WebAction Command from the list.
6. In the Properties tab, change the name to updateWebAction.
7. Select the Component Properties tab at the bottom of the editor.
8. Select ACTION_UPDATE for the Operation Name property.
Accept the defaults for the other two properties.
You have finished setting this property.
Note - A new entry is added under the Non-Visual Components node, and the Command Descriptor property is set. |
You now need to add the customerModel reference as an Auto Updating Model on the CustomerPage.
You accomplish this by populating the Page's Auto Updating Models property with the appropriate model reference--in this case, the customerModel reference that was created for you by the wizard as a result of the model association or field binding you specified.
1. Select the CustomerPage node.
2. Click the value area for the Auto Updating Models property.
The ellipsis button ("...") displays.
The Auto Updating Models custom editor launches.
Note that the Properties area is blank when this editor first displays.
5. Select customerModel from the Auto Updating Models combo box.
The property should now have the [customerModel] entry.
1. Expand the CustomerPage node.
2. Expand the Visual Components node.
3. Select the Visual Components node.
4. Select add a Hidden Field component using the Component Palette.
A hidden field is added to the CustomerPage's Visual Components node.
5. Rename the hidden field as hiddenKey.
6. Bind the hiddenKey field to the same model field that the customerTblCustomerNum static text field is bound.
7. Select the hiddenKey field.
8. On the property sheet, set the Model Reference property to customerModel by selecting from the drop down box.
9. Set the Model Field Binding property.
a. Click in the value area of the Model Field Binding property.
b. Click the ellipsis button to launch the Model Field Binding property editor.
10. Click the ellipsis button of the Read field name property to launch the Model Field Chooser editor.
11. Select CUSTOMER_TBL_CUSTOMER_NUM.
The read and write fields are populated with the CUSTOMER_TBL_CUSTOMER_NUM model field.
This completes setting the Model Field Binding property for the hiddenKey display field.
Because the static text field is not an HTML input field, it's value will not be submitted back to the server when the update button is clicked. And because the customer number is the key field in the database table, the update logic needs this key value in order to limit the update to a single database row. This value must be posted back along with the other input field values so that you can perform an update on the proper customer record rather than updating every record in the table. To achieve this, you will preserve the customer number field value in a hidden field, which will be posted back on form submit and mapped back into the CUSTOMER_TBL_CUSTOMER_NUM model field.
1. Expand the JSPs node under CustomerPage node.
2. Double-click the CustomerPage JSP to open it in the editor window.
3. Provide propercase labels for the fields.
Following is an example of minimal JSP formatting (only pertinent code is shown here). Some of the HTML source code is shown in bold for clarity.
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.