Business context plug-in

The business context plug-in helps generate the business context object. It leverages the MVC plug-in framework so that you can specify a customized version. The context plug-in must implement the PortletContextPlugIn interface which can be initialized and destroyed along with the WebSphere Commerce Portlet. A default implementation has been provided - com.ibm.commerce.foundation.client.portal.services.MVCPortletContextService.

For the MVCPortletContextService plug-in to convert the current language used in the Portal environment to the WebSphere Commerce specific langId, an additional Locale-to-LanguageId map is required. This map can be defined as a property file, WEB-INF/classes/language.properties, and has the following format:

Locale name = WebSphere Commerce language Id

For example, en = -1.

The MVCPortletContextService plug-in is using a fallback mechanism to determine the storeId to be used in the WebSphere Commerce business context. If there is no storeId currently set in the portlet session, then the plug-in uses the default defined in the portlet preference - .ContextDefault-storeId.

Portlet preferences can be used to initialize a business context object at runtime to build the basic set of WebSphere Commerce business context for use with the client library. When building the initial business context object, this service will search for any portlet preference name that starts with ".ContextDefault-" and use the string after that prefix as the name of the context name. The value of this context will be the actual value set for this preference name. For example, if .ContextDefault-storeId is the name of the context default and its value is 10001, then the context name will be storeId and the context value will be 10001.

The following are the recommended portlet preferences:

.ContextDefault-storeId

Defines the default WebSphere Commerce store identifier to be used in the business context when calling the client library. This preference is optional and has a default value of 0.

.ContextDefault-langId

Defines the WebSphere Commerce default language identifier to be used in the business context when calling the client library. this preference is optional and has a default value of -1.

Here is an example of how to load the business context object from a portlet session using the MVCPortletContextService context plug-in:

 PortletContextPlugIn portletContextPlugIn = (PortletContextPlugIn) MVCPortletServiceRegistry.singleton().getPortletService(iPortlet.getPortletName(), PortletPlugIn.TYPE_CONTEXT);
 BusinessContextType businessContextType = portletContextPlugIn.getBusinessContextType(getActionRequest());

Or, if you want to create a new business context, you can write code similar to the following example:

 BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType();
 ContextDataType contextData = CommerceFoundationFactory.eINSTANCE.createContextDataType();
 contextData.setName("storeId");
 contextData.setValue("10001");
 businessContext.getContextData().add(contextData);

Related concepts


WebSphere Commerce portlet action handler


WebSphere Commerce integration with WebSphere Portal


Use WebSphere Commerce services in portlets


WebSphere Commerce Portal integration event handlers

Related tasks


Calling a WebSphere Commerce service using the MVC portlet configuration file

Last updated: 25 November 2009