wc.render.declareRefreshController (initProperties)

The wc.render.declareRefreshController function declares a new refresh controller and initializes it with the specified initialization properties. The initialization properties are in addition to the new refresh controller's properties. A refresh controller control refresh area widgets, and listens to changes in the render context and model and decides whether the registered refresh areas must be updated.

Example

wc.render.declareRefreshController({
  id: "editShippingAdddressController",
  renderContext: wc.render.getContextById("editShippingAddressContext"),
  url: "",
  formId: "",
  modelChangedHandler: function(message, widget) {
    if(message.actionId in order_updated){
      widget.refresh();
    }
  },
  renderContextChangedHandler: function(message, widget) {
    var controller = this;
    var renderContext = this.renderContext;
    if (controller.testForChangedRC(["shippingAddress"])) {
      var addressId = renderContext.properties["shippingAddress"];
      widget.refresh({"addressId": addressId});
    }
  },
  postRefreshHandler: function(widget) {
  
  }
});

Parameters

initProperties
(Object) Contains any of the initialization parameters.
id
(String) The ID of the refresh controller.
renderContext
(renderContext) The render context object that is associated with this refresh controller.
url
(String) The URL that is called by the refresh function to retrieve the refreshed content for the refresh area widget. If the URL is dynamic, you can specify it, otherwise it can be defined at the beginning.
formId
(String) The ID of the form element that is posted to the URL.
modelChangedHandler
(Function) If defined, this function is called when a modelChanged event is detected. It is called once for each refresh area widget that is registered to this refresh controller. The function signature is (message, widget), where message is the model changed event message and widget is the refresh area widget.
renderContextChangedHandler
(Function) This function is invoked when any of the render context object attributes is changed. Implementors of this function must first check whether the attribute of interest is changed by using the testForChangedRC method. It is also responsible for calling the refresh function of the widget with any parameters that are required to perform the refresh.
postRefreshHandler
(Function) This function is invoked after the refresh area is successfully loaded and it gives the controller a final chance for executing some code. This function is equivalent to the "finally" method inside a try and catch block in Java.
testForChangedRC (propertyNames)
(Function) This function searches the specified array of property names for a render context property that is changed since the last time a render context changed event was detected. It returns a value of true if any of the specified render context properties is changed, and returns a value of false if none of the specified render context properties is changed. The function signature is (propertyNames), where propertyNames is an array of tested property names.