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
and
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
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 (struts-config- myservicemodule.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.
Client library enablement for AJAX
The Struts Ajax Component Service Action is a Struts Action implementation class that can be used to invoke a WebSphere 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
and 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
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.