Using linked Java objects for inter-model communication

Related Topics ...

Overview: Communicating Between Models

Using Events for Inter-Model Communication

Using the Session for Inter-Model Communication

Using Linked Models for Inter-Model Communication

The default behavior for a Linked Java Object (or any auto-instantiate Variable) is to create an instance of the object when you first try to access it. Your first point of access to this process is that we can set the "Instantiate via" input for the value. This is a method that is called when you have access the Variable and the Factory runtime code sees that the value is null.

We can initialize the value of the Linked Java Object variable from an object that was stored in the session data. This method first looks to see if such an object is already created and stored in the session data. It creates a new instance and stores it only if there was not one already there. This way, there is always only a single instance of the LJO class created for a given session, and it is shared between the models.

There is another technique that works equally well for models to shared a Linked Java Object. If one model calls

webAppAccess.getVariables().setObject("LJO_Name", sharedObject);

with an object that was passed to it via a public method, then it will never try to instantiate the object because the Variable will not be null when the first access is made to it.

This technique is used typically in a case where you have one model that is in charge -- it creates the object and has linked models to the other models. The master model would pass it to the others via public methods that they declare, and these public methods would set the Variables in their own models.