Designer 10.15 | webMethods CAF and OpenUI Development | User Interface Controls Concepts | Client-Side Libraries | CAF.Request Class
 
CAF.Request Class
The CAF.Request class extends Prototype's asynchronous request class, Ajax.Request, allowing asynchronous JSF requests. Its API is identical to Ajax.Request, and you can use it in the same way as Ajax.Request. See the Using the Ajax.Request class Prototype documentation.
You should use CAF.Request instead of Ajax.Request when making requests to the JSF servlet, adding a scope property to the request options, the client ID value of the JSF view root's client ID. For example, given a URL and the viewRootClientId, the following code alerts the response:
new CAF.Request(url, {
method: 'get',
onComplete: function(transport) {
alert("response: " + CAF.Request.extractResponseText(transport.responseText));
},
scope: viewRootClientId
});
To simulate a CAF command request, you can call the _createFragmentURL() method on the model object of a CAF control to create a URL that refreshes that control. For more information, see About the Client-Side Model. You can convert the current state of the control's form to a URL parameter string with Prototype's Form.serialize() method. With those two strings and after setting the CAF.Command.field() value to the ID of the command control to invoke, you can create a new CAF.Request that posts the current form state to the server and render the updated control fragment as a result. For example:
var m = CAF.model('#{activePageBean.clientIds['myCommand']}');
// set active command on form CAF.Command.field(m.form).value = m.id;
// calculate url and form post parameters
var url = m._createFragmentURL();
var formParams = Form.serialize(m.form);
// send request
var request = new CAF.Request(url, {
method: "post",
parameters: formParams,
scope: CAF.viewRootId(m.id),
onComplete: method(transport) {
CAF.Dialog.alert(request.extractResponseText());
}
});