WCS AJAX Framework

Posted by Hariharan Vadivelu on
WCS out of the box supports AJAX controllers which is essentially the Struts extensions.  The starter stores use the WCS DOJO extension for client side Web2.0 capabilities.
In this blog I wanted to demonstrate the WCS server side AJAX capabilities, although all of the sample stores extensively make use of DOJO and it's extensions, the server side AJAX controllers are really independent of the technology / AJAX library used on the client, this means you can use JQuery, YUI or any of your favorite AJAX library.

Before we get started with the server side coding, we need to understand how exactly WCS server side AJAX components work.

WCS AJAX Framework





















WCS Struts framework provides an important class named "AjaxAction" which is an extension of Action class.

This class file is packaged in Enablement-StrutsBaseLogic.jar
    AjaxAction class which extends the Action class.

You will define the controller the regular way you create any custom controller.
i.e
public class MyControllerCmdImpl extends ControllerCmdImpl implements MyControllerCmd


AJAX Controllers written using AjaxAction class will automatically call AjaxActionResponse.jsp as successview and AjaxActionErrorResponse.jsp as errorview, these two VIEW components will compose the response data in JSON format and send it back to client side.

1. For the sake of this example we will invoke a Controller in which we will set two parameters in response object.
In my performExecute method I set two parameters in the response object as follows.

        TypedProperty rspProp = new TypedProperty();
        rspProp.put("message1", "Message 1 Data");
        rspProp.put("message1", "Message 2 Data");

3. Make an entry in Struts Config to define this as an AJAX controller
As you can see the only difference is in the type parameter, for a regular controller you would define this as type="com.ibm.commerce.struts.BaseAction"

        <action parameter="com.ibm.commerce.sample.commands.MyControllerCmd" path="/AJAXController" type="com.ibm.commerce.struts.AjaxAction">
            <set-property property="authenticate" value="10551:0"/>
            <set-property property="https" value="10551:0"/>
        </action>
4. Make an entry in cmdreg table as follows.

insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET)
   values (10551,'com.ibm.commerce.sample.commands.MyNewControllerCmd',
                 'AJAX test',
                  'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl','Local');
5. Restart you server instance and hit the new controller URL, following message will be printed in the browser.

The data that get's printed is the JSON representation of all response parameters you set from your controller. in an ideal world some AJAX client code would read this JSON data and paint it on the UI.

/* { "langId": ["-1"], "message1": "Message 2 Data", "storeId": ["10551"] } */

Resources

WCS Best Practices in Web 2.0 stores


10 comments:

  1. Your blog is very useful. i got more than information. its really wonderful blog. pls added more than tips. Nice sharing.Thanks for your valuable posting. i'm working in a cms in chennai.Here providing very low price cms , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail info@excelanto.com.

    ReplyDelete
  2. Thanks For Your valuable posting, it was very informative. i am working in Erp Software company In India

    ReplyDelete
  3. Thanks for your valuable posting.I have collect more than information from your website. It's really wonderful blog. please added more than tips. i'm working in a cms in chennai.Here providing very low price CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail info@excelanto.com.

    ReplyDelete
  4. Thanks for your valuable posting.I have collect more than information from your website. It's really wonderful blog. please added more than tips. i'm working in a cms in chennai.Here providing very low price CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail info@excelanto.com.

    ReplyDelete
  5. Can u please tell how to pass parameter to that controller command

    ReplyDelete
  6. It was very nice blog to learn about SAP HR.Thanks for sharing new things.SAP HR

    ReplyDelete
  7. nice post.I am impressed by the quality of information on this website.Thanks for sharing this post
    Trading erp software in chennai

    ReplyDelete