Adding Insert, Save, and Delete Buttons
Now add the buttons that let users insert, save, and delete MovieRoles. When you're done, it should look like the following:
- Inside the form, add three image buttons below the Role Name text field.
- Inspect the first active image element.
- Bind the filename attribute to the text (including the quotes) "DBWizardInsert.gif".
- Follow the same procedure to set the second image's filename attribute to the text (including the quotes) "DBWizardUpdate.gif".
- Set the last image's filename attribute to the text (including the quotes) "DBWizardDelete.gif".
- Copy the saveChanges method from the Main.java class and paste it into the MovieDetails.java class:
- Bind movieRoleDisplayGroup.insert to the Insert/New image's action attribute.
- Bind the saveChanges method to the "Save to database" image's action attribute.
- Bind movieRoleDisplayGroup.delete to the Delete image's action attribute.
The DisplayGroup class defines the actions insert and delete that you'll bind to the Insert/New and Delete buttons. It doesn't, however, provide a save method. You'll have to provide that yourself.
public void saveChanges() throws Exception { try { this.session().defaultEditingContext().saveChanges(); } catch (Exception exception) { System.err.println("Cannot save changes "); throw exception; } }
Table of Contents Next Section