Specifying Default Values for New Enterprise Objects
When new enterprise objects are created in your application, it's common to assign default values to some of their properties. For example, in your Movies application it makes sense to assign a default value for the title attribute so a new movie won't be displayed in the list of movies as a blank line.You could write an action method for the Insert/New button instead of binding it directly to the display group insert action method. In the custom action, you would create a new Movie object, assign default values to it, and then insert the new object into the display group. However, there are two additional ways to specify default values for new enterprise objects, without making explicit assignments:
- Assign default values in the enterprise object class.
- Specify default values using a display group.
On the other hand, if the default values are specific to an application or to a particular user interface, explicitly initialize the object in code or specify the default values using a display group. In the Movies application, the need for default values is motivated by Main's user interface: you need to provide a default value so users can tell when a newly inserted record is selected. In another situation, you might not want a new movie to have a default title; you might instead want a new movie's title to be blank.
- Open Main.java in Project Builder.
- Add the following constructor:
public Main() { super(); MutableHashtable defaultValues = new MutableHashtable(); defaultValues.put("title", "New Movie Title"); movieDisplayGroup.setInsertedObjectDefaultValues(defaultValues); }
This method assigns the value "New Movie Title" as the default value for a new movie's title attribute. When movieDisplayGroup inserts a new movie (as it does when a user clicks the Insert button), it creates a new movie and assigns this default value to that movie.
Table of Contents Next Section