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 controls refresh area widgets, and listens to changes in the render context and model and decides if the registered refresh areas should 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
registered to this refresh controller. The function signature is
(message, widget)
, wheremessage
is the model changed event message andwidget
is the refresh area widget. - renderContextChangedHandler
- (Function) This function is invoked when any of the render context object attributes has changed. Implementors of this function should first check if the attribute of interest has changed 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 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 has 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 have changed,
and returns a value of false if none of the specified render context
properties have changed. The function signature is
(propertyNames)
, wherepropertyNames
is an array of tested property names.