Documentation Archive Developer
Search
Table of Contents Previous Section

Bindings in the Editing Part

The text fields in the editing part are all bound to attributes of the movieDisplayGroup's selectedObject-the movie on which the user clicked. Typing new values into these fields updates the Movie enterprise object. To actually save the updated values to the database, the user must click the "Save to database" button.

  1. Inspect the middle image button.

    Its action attribute is bound to the action method saveChanges.

  2. Look in the Main.java class to see how saveChanges is implemented.

    The method (shown below with comments omitted) simply saves any changes that have been made to movieDisplayGroup's objects to the database.

    public void saveChanges() throws Exception {
        try {
            this.session().defaultEditingContext().saveChanges();
        }
        catch (Exception exception) {
            System.err.println("Cannot save changes ");
            throw exception;
        }
    }
    

    this.session() returns a Session object that represents a connection to the application by a single user. A Session object provides access to an EditingContext object. The expression

    this.session().defaultEditingContext().saveChanges();
    

    sends a saveChanges message to the Session's defaultEditingContext. This default EditingContext object manages graphs of objects fetched from the database, and all changes to the database are saved through it. For more information, see the EditingContext class specification in the Enterprise Objects Framework Reference.

    An EditingContext's saveChanges method uses other Enterprise Objects Framework objects to analyze its network of enterprise objects (Movie objects referenced by the application) for changes and then to perform a set of corresponding operations in the database. If an error occurs during this process, saveChanges throws an exception. Main.java's saveChanges method simply raises the exception, having the effect of returning a diagnostic page. You could return an error page that explains the reason for the save failure instead, but the application in this tutorial uses the default behavior.

  3. Inspect the first and third image buttons to see what their action attributes are bound to.

    They are bound to movieDisplayGroup.insert and movieDisplayGroup.delete, respectively. The DisplayGroup insert method creates a new enterprise object, then inserts it into the display group's list of objects just past the current selection. The DisplayGroup delete method deletes the display group's selected object. These changes happen only in memory-not in the database. To actually insert a new row in the database (or delete a row), the user must click the "Save to database" button, invoking saveChanges on the session's EditingContext. The editing context analyzes the enterprise objects in memory; determines if any objects have been added, updated, or deleted; and then executes database operations to sync the database with the application.

Table of Contents Next Section