JavaScript API Reference

Buffalo

Buffalo class is the only one for most cases.

Buffalo(gateway, async, events, options)

Parameter nameParameter typeDescriptionRequired?Default
gatewaystringthe address of bfapp servlettrueN/A
asyncbooleanif it's a asynchronous callfalsetrue
eventsobjectthe events handlerfalsesee howto
optionsobjectother optionsfalsetimeout=10000

This is the constructor for Buffalo, exmple use:

var buffalo = new Buffalo("/bfapp/buffalo");

To make a synchronized call:

var buffalo = new Buffalo("/bfapp/buffalo", false);

remoteCall(service, params, callback)

remoteCall will make a remote call using the service with params. It will use callback function to handle the result.

Parameter nameParameter typeDescriptionRequired?Default
servicestringthe service name and method name, format is "serviceName.methodName"trueN/A
paramsArraythe parameter for the remote calltrueN/A
callbackfunctionthe call back function, will take Buffalo.Reply as parametertrueN/A

Code demo:

buffalo.remoteCall("helloService.hello", ['Michael'], function(reply) {
    alert(reply.getResult());
})

The reply.getResult() will give you exactly the same object model defined in Java in a javascript way.

Or:

buffalo.remoteCall("helloService.hello", ['Michael'], myfunc);
function myfunc(reply) {
  alert(reply.getResult());
}

setEvents(events)

setEvents will customize the event handler for the buffalo instance.

Parameter nameParameter typeDescriptionRequired?Default
eventsobjectthe event hanlderstrueN/A
buffalo.setEvents({onLoading:myloading}})
function myloading(state) {
  if (state) {window.status = "loading..."; } 
  else {window.status = "load completed."; }
}

Or you can just like this:

buffalo.events["onLoading"] = myloading;

bindReply(service, params, elementId)

bindReply will make a remote call and bind the result to the element.

Parameter nameParameter typeDescriptionRequired?Default
servicestringthe service name and method name, format is "serviceName.methodName"trueN/A
paramsArraythe parameter for the remote calltrueN/A
elementIdstringthe element which you need bind value totrueN/A

For example: call the simpleService.provincesNames and bind the result to id=select_provinde form select element. You can read more about binding.

buffalo.bindReply("simpleService.provincesNames",[],"select_province");

switchView(viewName)

switchView will get the viewName page and load the content to div(id=body). This operation will be added to browser history so that the back/forward button can be used.

Parameter nameParameter typeDescriptionRequired?Default
viewNamestringthe view urltrueN/A
buffalo.switchView("help.html");

switchPart(viewName, partId, addToHistory)

switchPart will get the viewName page and load the content to element(id=partId), if addToHistory is true, it will add this operation to browser history so that the back/forward button can be used.

Parameter nameParameter typeDescriptionRequired?Default
viewNamestringthe view urltrueN/A
partIdstringthe div id which will be replacedtrueN/A
addToHistorybooleanif this operation add to browser history?trueN/A