Client library enablement for Struts

The Struts Component Service Action is a Struts Action implementation class that can be used to invoke a component service from a traditional Web application.The Struts Component Service Action is a subclass of com.ibm.commerce.struts.BaseAction. This service action overrides the invokeService() method. The new implementation of invokeService() passes the input parameters map to a configured client library method which will perform a service and return an output parameter map.

After the request has been completed, the default behavior of the service action is to cause a redirect to the URL specified by either the redirecturl or URL input parameter. This is done by adding RedirectView as the value of an output parameter named viewTaskName before returning the output map at the end of the invokeService() method. This causes the base action implementation to invoke the RedirectView command.

The Struts Component Service Action implementation has the following class name:

com.ibm.commerce.struts.ComponentServiceAction

HCL Commerce Version 9.0.1.0 or latercom.ibm.commerce.struts.v2.ComponentServiceAction

A new Struts Action implementation provides access to the Web-friendly methods of service modules. It is recommended that a new Struts configuration file is created for each service module.

For example, create a file named struts-config-myservicemodule.xml in the WEB-INF directory.

HCL Commerce Version 9.0.1.0 or laterFor example, create a file named struts-wcs-webapplication-myservicemodule.xml and add a reference to thisin the web application struts configuration entry file, with the following code snippet:
<include file="struts-wcs-webapplication-myservicemodule.xml"></include> 
The struts configuration entry files for each web application are:
CommerceAccelerator
CommerceAccelerator\WEB-INF\classes\struts-accelerator.xml
OrganizationAdministration
OrganizationAdministration\WEB-INF\classes\struts-orgadmin.xml
SiteAdministration
SiteAdministration\WEB-INF\classes\struts-siteadmin.xml
Stores
Stores\WEB-INF\classes\struts-stores.xml

Struts client service plug-in

The Struts configuration file must define a component plug-in with the service module client facade and an ID to refer to the service module. Action mapping parameters are defined in the form id.clientmethod, where id is the service module ID and client method is a Web-friendly method contained in the service module client facade. The following example provides an example of the component plug-in configuration and an action mapping parameter definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software
Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

<!-- Data Sources -->
<data-sources>
</data-sources>

<!-- Form Beans -->
<form-beans>
</form-beans>

<!-- Global Exceptions -->
<global-exceptions>
</global-exceptions>

<!-- Global Forwards -->
<global-forwards> 
<forward className="com.ibm.commerce.struts.ECActionForward"
name="Example" path="/Example.jsp"/>
</global-forwards>

<!-- Action Mappings -->
<action-mappings
type="com.ibm.commerce.struts.ECActionMapping">
<!-- Struts Service Module Action Test 
Run a webfriendly method from MyServiceModule -->
<action
parameter="myservicemodule.webfriendlymethod" 
path="/Example" 
type="com.ibm.commerce.struts.ComponentServiceAction">
<set-property property="authenticate" value="0:0"/>
<set-property property="https" value="0:1"/>
</action>

</action-mappings>

<!-- Define the MyServiceModule client facade -->
<plug-in className="com.ibm.commerce.struts.ComponentPlugIn">
<set-property property="componentId"
value="myservicemodule"/>
<set-property property="clientFacadeClassName"
value="com.mycompany.commerce.myservicemodule.facade.client.MyServiceModuleFacadeClient"/>
</plug-in>

</struts-config>
The parameter attribute defines the client library that is to be used. The clientMethod parameter defines the client library method.
HCL Commerce Version 9.0.1.0 or laterThe component plug-in with the service module client facade and an ID to refer to the service module must be added to ComponentPlugins.xml file. Action mapping parameters are defined in the form id.clientmethod, where id is the service module ID and clientmethod is a Web-friendly method contained in the service module client facade. The following example provides an example of the component plug-in configuration in ComponentPlugins.xml:
<?xml version="1.0" encoding="UTF-8"?> 
<ComponentPlugins> <!-- Define the MyServiceModule client facade --> 
<plug-in className="com.ibm.commerce.struts.ComponentPlugIn" componentId="myservicemodule" 
clientFacadeClassName="com.mycompany.commerce.myservicemodule.facade.client.MyServiceModuleFacadeClient"/> 
</ComponentPlugins>
The following example provides an example of the action mapping in struts configuration files:
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> 
<struts>
  <package extends="wcs-stores" name="my-services" namespace="/">

    <action class="com.ibm.commerce.struts.v2.ComponentServiceAction" name="Example">
      <param name="authenticate">0:0</param>
      <param name="https">0:1</param>
      <param name="parameter">myservicemodule.webfriendlymethod</param>
    </action>

  </package>
</struts>
The parameter action parameter defines the client library that is to be used and the method to be called.

Client library enablement for AJAX

The Struts Ajax Component Service Action is a Struts Action implementation class that can be used to invoke an HCL Commerce service using an Ajax style browser request. All URL-enabled services are enabled for AJAX support and just need to be configured.

The Struts Ajax Component Service Action is a subclass of:

com.ibm.commerce.struts.BaseAction

HCL Commerce Version 9.0.1.0 or latercom.ibm.commerce.struts.v2.BaseAction

This action overrides the invokeService method. The new implementation of invokeService passes the input parameters map to a configured client library method which calls a service and returns an output parameter map.

Once the request is complete, it is forwarded to a JSP file that composes the service response. The service response JSP file creates a JSON object out of the values found in the response Map.

The Struts Ajax Component Service Action has the following class name:

com.ibm.commerce.struts.AjaxComponentServiceAction

HCL Commerce Version 9.0.1.0 or latercom.ibm.commerce.struts.v2.AjaxComponentServiceAction

A Struts action that uses the Ajax Component Service Action implementation is configured in struts-config.xml as shown in the following XML sample:


<action
  
parameter="com.ibm.commerce.catalog.facade.client.CatalogFacadeClient"
   path="/AjaxChangeProduct"
   type="com.ibm.commerce.struts.AjaxComponentServiceAction">
      <set-property property="clientMethod"
value="changeProduct"/>
</action>
The parameter attribute defines the client library that is to be used. The clientMethod parameter defines the client library method.
HCL Commerce Version 9.0.1.0 or later
<action class="com.ibm.commerce.struts.v2.AjaxComponentServiceAction" name="AjaxPersonChangeServiceAddressAdd">
      <param name="authenticate">0:0</param>
      <param name="https">0:1</param>
      <param name="parameter">member.addAddressForPerson</param>
    </action>
<action
The parameter action parameter defines the client library that is to be used and the method to be called.