Shared Variable Builder

 

In this topic ...

How do I...

Specifying Inputs

Objects this Builder Creates

Use this builder to share data between model or portlet instances, or between WebSphere Portlet Factory and non-factory code. The Shared Variable builder will publish the value of a variable to the session, the request, a global data item (Java "static" field) or to a custom, user-defined repository.

The Shared Variable Builder creates a two-way link between a variable and an external data store. This linkage allows the variable to be shared among models in a session, or to connect to some non-factory code that uses session or request attributes.

Each time the variable associated with this builder is read, its value is pulled in from the specified external storage location (session, request, etc.). Similarly, each time the variable is changed, the new value is written to the external store.

Your model code can access the variable just like any other variable, but its value is kept in synch with the external shared copy. Other models will see changes your model makes to the variable, and you ll be able to see the most recent value set by other models.

 

How do I...

Share the value of a variable with other WebSphere Portlet Factory  portlets ?

Add a Shared Variable Builder Call to a model and point it at the variable whose value you want to share.

Choose "Session" for the Scope input, and choose a meaningful Unique ID value such as: companyname.application.variable_role.

Repeat this process in the other portlet models, using the same Unique ID value in all the Shared Variable builder calls. The value of the "Use Outer Session" input should be left as checked (enabled.)

Use an LJO as a bean input to a JSP tag ?

We can use Shared Variable to export an LJO to the session or request so it can be used by a JSP tag or custom taglib call.  To do this, add a Shared Variable builder to a model and select the LJO s name (e.g., "myBean") as the Variable input value.

Use either "Session" or "Request" as the Scope input value. In your page, you include code similar to the following to access the LJO:

 <jsp:usebean id="myBean" class="com.mycompany.myBeanClassName" scope="session" />

 <jsp:getProperty name="myBean" property="customerName" />

Classes that are shared with JSP code must be available on the classpath for the WebApp. Code that is compiled into work/classes is usually loaded by the Factory's dynamic class loader, which is not available to the application server. We can work around this by putting your LJO classes under  WEB-INF/classes, or in a  JAR in WEB-INF/lib.

Use A Request Attribute as a Variable Value?

Associate a Shared Variable Builder call with the variable you want to connect to the request attribute. Use the name of this attribute as the Unique ID input value, (for example: bowstreet.ContextURL) to have a variable whose value is a URL pointing at the root of this application s servable content.

 

Specifying Inputs

This Builder takes the inputs described in the table below. For help on inputs common to many or all Builders such as those in the Properties and HTML Attributes input groups, see "Using the Builder Call Editor"

Input Name Description
Name Enter a name for this Builder call. The Designer displays this name in the Builder Call List.
Variable Use the Picker to choose the model variable to be shared.

This variable will be connected to the external store.

Scope Select the scope of sharing for the variable data. You can choose one of the following scopes:

  • Session To share variable data to an attribute of the HttpSession object

  • Request To share variable data to as an attribute of the current HttpServletRequest object

  • Application  To share variable data as a Java "static" in which a global data store is used to share the data across all programs in the same JVM

  • Custom To specify a custom class which can load/store the variable values. This is an advanced option and can generally be ignored.  You provide a Java class that implements the com.bowstreet.builders.webapp.methods.VariableDataStore interface. An instance of this class will be used to load and store the variable s value
Unique ID Specify a string used to identify the data in the external store, e.g., as the name of the session or request attribute in those scopes.

This string should be chosen so that it won t collide with other values. unless you intend for such values to be used as the basis of this variable.

This ID is a key used to locate the variable s value. The type of key depends on the value of the Scope input. For example:

  • Request or Session mode - Name of the request/session attribute

  • Application mode -Key in an internal Hashtable

  • Custom mode - Interpretation is up to the custom class.
Custom Class Available when the Scope  is "Custom".

This lets you specify a custom class used to load and store the variable s value.

Choose the name of the class that will do the data loading/storing

this class must implement the interface:

 com.bowstreet.builders.webapp.methods.VariableDataStore

Custom Context Available when the Scope  is "Custom".

A custom class may require a "context" value to allow it to manage its data. This value is dependent on the class chosen as the "Custom Class" input.

This input is intended to provide contextual information to the custom data store implementation what sort of value (if any) is determined by the implementation chosen by the value of the "Custom Class" input.

See the documentation for the class chosen there for details on what context value, if any, is required

Page Available when the Scope  is "Request".

Optional: Select a page on which to place an onLoad event handler which causes the variable s value to be re-published to the corresponding request attribute each time that page is loaded.

Each time the named page loads, the variable s value will be re-published into the corresponding request attribute.

Alternatively, we can call <buildername>.rePublishVariableValue to set the value, (for example in an OnRequest handler).

Advanced
Use Outer Session Available when the Scope  is "Session".

This input is relevant only if the model is being run as a portlet.

In portlet containers, there are usually two levels of session data: an "inner" scope which is local to each portlet instance, and an "outer" session scope that is shared by all portlets.

When this input is enabled,  the shared variable value will be stored in the outer session, making it potentially available for all active portlets. When this input is disabled, the data will be kept in the inner session context.

Disable this input to use the inner session context if you are using session data to communicate with legacy code in your portlet (not other portlets) and want to avoid the possibility of collisions in the shared outer space.

  • Enabled - To use the outermost session object for data storage. In a portal this will be the session managed by the portal. This setting allows portlets to share data.

  • Disabled - To use the default "local" session. In the portlet case, this will limit session data visibility to the portlet in question.

 

Objects this Builder Creates

Linked Java Objects

  • <buildername> - LJO used internally by the builder to fetch and store the shared variable value.