WebSphere Commerce EnterpriseWebSphere Commerce Professional

Adding properties to a model object

The data model is used to cache business objects on the client. The TelesalesModelManager class provides access to the model and contains convenience methods for accessing and updating child objects. The default IBM Sales Center data model contains model objects that represent the operator, customers, orders, products and other commonly used objects.

About this task

To add additional properties to an existing IBM Sales Center model object:

Procedure

  1. Choose a unique property name. To ensure that the property name will not collide with a default property name, it is suggested to prefix the property names with ext_.
  2. Use the setData and getData methods on the ModelObject class to add, remove and reference your new property.

Results

For example:


//Defining a key to add a property
public static final String PROP_CUSTOM_ID = "ext_custome_id";

//Setting the property against the key
public void setCustomData(Object data) {
          setData(PROP_CUSTOM_ID, data);
     }

//Getting the property by using the key
public Object getCustomData() {
         getData(PROP_CUSTOM_ID);
     }

If the new property is actually a list, then use the ModelObjectList class to collect the list of values together. This ensures that notifications for changes are sent to objects that are listening for changes, when changes are made to the list or to any of the model objects in the list.

This example defines a key to add a model object list:


public static final String PROP_LIST_ITEMS = "list_items"

//Getting the model object list property
public ModelObjectList getItemslObjectList() {
        return (ModelObjectList) getData(PROP_LIST_ITEMS);
    }

This can be also used to set data inside the model object list. An example: getItemslObjectList().addData(data)

If a property has been marked as being a user data property by using the ModelObject.addUserDataProperty method, then it will be passed to the server through the Userdata section of the Business Object Document. These name-value pairs will automatically show up in the request properties of the controller command.

Note that IBM Sales Center client model objects are retrieved by using TelesalesModelManager. To get a singleton instance of this class, use:


TelesalesModelManager myModelManager =
TelesalesModelManager.getInstance();