Application Techniques



Updating Rows in a View Using a Dialog

How to enable users to update rows in a data view by using an update dialog.

About this technique

Details

Category

HTML Client Techniques> HTML-based views

Description

You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on using HTML-based views in the Programmer's Guide

The example uses two pages:

Binding controls in separate pages to the same database   Top of page

In order for the Update dialog to modify the data that is displayed in the original page, both pages access the same database table. The following describes how to bind a data view in the pgCallUpdateDialog page to the contacts database table and how to bind text and label controls in the pgUpdateDialog page to the columns of the same table.

Bind the data view in pgCallUpdateDialog to a database table as follows:

  1. Add a data view to the form by selecting the Data View icon. Use the Properties Editor's Data View tab to name it dvContacts, and to specify that the data comes from the contacts database table.

  2. In the data view, add four event link type labels (id, firstname, lastname, and email). The labels display the data from four columns in the contacts table.

    Use the Properties Inspector's Label tab to specify the name of the label, its type (select Event Link) and expression (for example, contacts.id for the id label).

  3. Associate the form with the contacts database table by selecting the Data icon on the left (vertical) tool bar, and selecting contacts from the pull-down menu.

Bind the data in pgUpdateDialog to the same database table as follows:

  1. Associate the form with the contacts database table by selecting the Data icon on the left (vertical) tool bar, and selecting contacts from the pull-down menu.

  2. Add a label (id) to the form. Select the Properties Inspector's Label tab and set the Expression field to contacts.id, causing it to display the id column of each row.

  3. Add three text fields to the form. Select the Properties Inspector's Field tab and set the Data column field to firstname, lastname, and email respectively.

Invoking the update dialog   Top of page

When the pgCallUpdateDialog page first loads up, it triggers the pageReguestBegin event. When the user clicks on any of the labels, this action triggers an event link event, which causes the following sequence of code execution:

  1. The pageReguestBegin event executes again,

  2. followed by the code for that label control,

  3. and then followed by pageReguestBegin yet again.

The code for the pageRequestBegin event and the handle_firstname_eventLinkPerformed() method is shown below. The code for the other label controls are the same as for the firstname label.

  protected void pageRequestBegin(AgiHttpServletRequest req, AgiHttpServletResponse res) throws Exception 
  { 
     String id = (String) getSessionValue("id"); 
     if (id != null) 
     { 
        agScriptHelper.openWindow("pgUpdateDialog.html", "new",  
           "width=550,height=225,resizable=no,menubar=no,scrollbars=no,status=no",  
           "contacts.id=" + id, null); 
        removeSessionValue("id"); 
     } 
     else 
        dvContacts.refreshRows(); 
  } 
   
  private void handle_firstname_eventLinkPerformed(AgpEventLinkEvent evt) throws Exception 
  { 
     String[] values = evt.getServletRequest().getParameterValues("id"); 
     if (values != null) 
        setSessionValue("id", values[0]); 
  } 

Notes about the code

The following notes are presented in the order of code execution, beginning at the point where the user clicks a First Name label.

Updating rows from the update dialog   Top of page

The following code describes the method in pgUpdateDialog that updates the rows, refreshes the data set in the calling page (pgCallUpdateDialog), and closes the Update dialog. The code runs when the user clicks the OK button in the dialog.

  private void handle_OK_pageActionPerformed(ActionEvent evt) throws Exception 
  { 
     // Save the new record. 
     agData.updateRows(); 
      
     // Tell the page that called this one to refresh its dataset. 
     writeScript("window.opener.location=\"pgCallUpdateDialog.html\""); 
   
     // Close. 
     agScriptHelper.closeWindow(); 
      
  } 

Notes about the code






Copyright © 2000, SilverStream Software, Inc. All rights reserved.