Friday, February 28, 2014

Struts actions AjaxComponentServiceAction !!

   
This is not your usual forward mapping to a JSP or an action mapping to a command
 This is an example of calling a component service from an ajax style request and this must be define a struts action in struts-config-ext.xml. Plese find below a snippet.

   <action parameter="member.updateAddressForPerson" path="/AjaxPersonChangeServiceAddressUpdate" type="com.ibm.commerce.struts.AjaxComponentServiceAction">
            <set-property property="authenticate" value="0:0"/>
            <set-property property="https" value="0:0"/>
            <set-property property="csrfProtected" value="0:0"/>
        </action>

e.g. Service actions above can be used in refresh areas example below. After completion of the command, the struts action forwards the JSP file  that generates a JSON , with response property containing success or failure details.

    wc.service.declare({
        id: "AjaxUpdateAddressForPerson",
        actionId: "AjaxUpdateAddressForPerson",
        url: getAbsoluteURL() + "AjaxPersonChangeServiceAddressUpdate",
        formId: ""

    /**
     * hides all the messages and the progress bar
     * @param (object) serviceResponse The service response object, which is the
     * JSON object returned by the service invocation
     */
        ,successHandler: function(serviceResponse) {
            AddressHelper.updateOrderAfterAddressUpdate();
            MessageHelper.hideAndClearMessage();
            cursor_clear();
        }
     /**
     * display an error message
     * @param (object) serviceResponse The service response object, which is the
     * JSON object returned by the service invocation
     */
        ,failureHandler: function(serviceResponse) {

            if (serviceResponse.errorMessage) {
                MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
            }
            else {
                 if (serviceResponse.errorMessageKey) {
                    MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
                 }
            }
            cursor_clear();
        }

    }),

Reference: For more information on checkout controls, please review IBM infocenter.

2 comments:

  1. Me encanta todo lo que cuentas en el post, es muy interesante y me encantaría que explicaras más sobre el tema.

    ReplyDelete
  2. Muy chulo el artículo, contiene información muy interesante, gracias por tu interés

    ReplyDelete