Invoking Controller Commands From Store JSP

Tuesday, 21 April 2015

Invoking Controller Commands from Store JSP

WCS business logic layer provides various artifacts like Controller Commands, SOI Services, BOD (SOA) Services and REST Services to execute business logic. These commands and services can be invoked from view layer (For ex: Web Store) using Struts, JSTL tag libraries and WCS framework. Struts is used for managing view – controller interaction. In this post we will see how to invoke controller command from a Store JSP. Assume you have created a custom command implementation com.mycompany.MyOrderItemAddCmdImpl for com.ibm.commerce.orderitems.commands.OrderItemAddCmd, to add an item to shopping cart. The list below provides high level steps required to invoke this custom command from one of the Store JSP (with StoreId = 10001)
  • Register this command in CMDREG table by executing following insert statement.
insert into cmdreg values(10001,'com.mycompany.MyOrderItemAddCmdImpl','description','com.ibm.commerce.orderitems.commands.OrderItemAddCmd',null,null,null, 0);
  • Update struts-config-ext.xml in Stores.war/web-inf folder with following entry
<action parameter="com.ibm.commerce.orderitems.commands.OrderItemAddCmd" path="/MyOrderItemAdd" type="com.ibm.commerce.struts.BaseAction"> <set-property property="credentialsAccepted" value="10001:P "/> <set-property property="authenticate" value="10001:1"/> <set-property property="https" value="10001:1"/> </action> • /MyOrderItemAdd is the mapping name which will be used in the URL to invoke MyOrderItemAddCmdImpl command. • Set credentialsAccepted value to <storeId>:P, if this command can be executed by partially authenticated user (Remembered user) • Set authenticate value to <storeId>:1, if this command needs to be executed by only logged in user • Set https value to <storeId>:1, if this command needs to be executed over secure HTTPS protocol. • Set type = “com.ibm.commerce.struts.BaseAction” if the command needs to be invoked in Web1.0 style. When a controller command is invoked with BaseAction, ‘URL’ query parameter is mandatory. Once the command execution completes, user will be redirected to the view specified with ‘URL’ query parameter. • Set type = “com.ibm.commerce.struts.AjaxAction” if the command needs to be invoked in Web2.0 style (Ajax request). When a controller command is invoked with AjaxAction, after execution of controller command, request will be forwarded to AjaxActionResponse.jsp or AjaxActionErrorResponse.jsp, which takes response properties from command, converts to JSON object and returns JSON response to client.
  • You can now POST form from JSP to below URL, by setting action attribute of form to /MyOrderItemAdd.
https://localhost/webapp/wcs/stores/servlet/MyOrderItemAdd?catentry_id=12345&quantity=1&URL=ShoppingCartPageView&errorViewName=ErrorPageView Tracing the request: webapp/wcs/stores maps to Stores.war. So request is handled by Store Webapp. ECActionServlet is configured to handle incoming requests with path /servlet/* in web.xml and is the entry point for the request. BaseAction / AjaxAction handles the request and reads struts-config-ext.xml entry and looks for /MyOrderItemAdd MyOrderItemAdd maps to interface name in struts-config-ext.xml. CMDREG contains the implementation class for this interface name. MyOrderItemAddCmdImpl command gets invoked. Query Parameters / Form post parameters are set into RequestProperties by base ControllerCommandImpl and will be available for the command to execute the business logic. ResponseProperties will be set after successful execution of the command.

No comments:

Post a Comment

Newer Post Home Subscribe to: Post Comments (Atom)

Total Pageviews

About Me

Guruprasad View my complete profile

Blog Archive

  • ▼  2015 (7)
    • ▼  April (5)
      • Caching Store level or Site level widgets.
      • Use of pageLayoutCache JSTL tag and PageDesignMeta...
      • Invoking REST Services ( PUT / POST / DELETE ) fro...
      • Invoking REST Services (GET Method ) from Store JSP
      • Invoking Controller Commands from Store JSP

Tag » Com.ibm.commerce.struts.base Action Execute View Cmn0203e Command Not Found