How to enable users to update rows in a data view by using an update dialog.
You can run this technique code from:
NOTE First make sure that database is running on your localhost SilverStream Server | |
See the chapter on using HTML-based views in the Programmer's Guide |
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:
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).
Bind the data in pgUpdateDialog to the same database table as follows:
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:
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]); }
The following notes are presented in the order of code execution, beginning at the point where the user clicks a First Name label.
getSessionValue("id")
returns null because id has not yet been set.
dvContacts.refreshRows()
.
handle_firstname_eventLinkPerformed()
runs.
getServletRequest()
.
getParameterValues("id")
to get that clicked row's id value.
setSesionValue()
.
pageRequestBegin()
runs again, the id session value is now set.
openWindow()
. For the query parameter, specify the row by its id value.
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(); }
closeWindow()
. This utility object generates JavaScript to perform JavaScript functions.