Business context plug-in

The business context plug-in helps generate the business context object. It uses 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 ended along with the WebSphere Commerce Portlet. The default implementation is com.ibm.commerce.foundation.client.portal.services.MVCPortletContextService.

For the MVCPortletContextService plug-in to convert the current language that is used in the Portal environment to the WebSphere Commerce specific langId, an extra Locale-to-LanguageId map is required. This map can be defined as a property file, WEB-INF/classes/language.properties. The file format is 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 that is defined in the portlet preference, .ContextDefault-storeId.

Use Portlet preferences to initialize a business context object at run time with WebSphere Commerce business context for use with the client library. The service searches for any portlet preference name that starts with .ContextDefault- and uses the string after that prefix as the name of the context name. The value of this context is the value that is 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 is storeId and the context value is 10001.

Portlet preferences:
.ContextDefault-storeId
Defines the default WebSphere Commerce store identifier that is used in the business context to call the client library. This preference is optional. The default value is 0.
.ContextDefault-langId
Defines the WebSphere Commerce default language identifier that is used in the business context to call the client library. This preference is optional. The default value is -1.
Example: Load the business context object from a portlet session by using the MVCPortletContextService context plug-in
 PortletContextPlugIn portletContextPlugIn = (PortletContextPlugIn) MVCPortletServiceRegistry.singleton().getPortletService(iPortlet.getPortletName(), PortletPlugIn.TYPE_CONTEXT);
 BusinessContextType businessContextType = portletContextPlugIn.getBusinessContextType(getActionRequest());
Example: Create a business context
 BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType();
 ContextDataType contextData = CommerceFoundationFactory.eINSTANCE.createContextDataType();
 contextData.setName("storeId");
 contextData.setValue("10001");
 businessContext.getContextData().add(contextData);