📄 jsapi.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Buffalo AJAX - JavaScript API</title>
<style type="text/css" media="all">
@import url("./css/maven-base.css");
@import url("./css/maven-theme.css");
@import url("./css/site.css");
</style>
<link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body class="composite">
<div id="banner">
<a href="index.html" id="bannerLeft">
<img src="images/buffalo-title.gif" alt="" />
</a>
<a href="http://sourceforge.net" id="bannerRight">
<img src="http://sflogo.sourceforge.net/sflogo.php?group_id=178867&type=1" alt="" />
</a>
<div class="clear">
<hr/>
</div>
</div>
<div id="breadcrumbs">
<div class="xleft">
Last Published: 10/08/2006
</div>
<div class="xright"> <a href="http://www.amowa.net/buffalo/zh">Chinese Docs</a>
</div>
<div class="clear">
<hr/>
</div>
</div>
<div id="leftColumn">
<div id="navcolumn">
<h5>Quick Start</h5>
<ul>
<li class="none">
<a href="tutorial.html">1 Minute Tutorial</a>
</li>
<li class="none">
<a href="http://demo.amowa.net/buffalo-demo/">Demo</a>
</li>
<li class="none">
<a href="download.html">Download</a>
</li>
<li class="none">
<a href="features.html">Features</a>
</li>
<li class="none">
<a href="faq.html">FAQ</a>
</li>
</ul>
<h5>Mastering Buffalo</h5>
<ul>
<li class="none">
<a href="best_practice.html">Best Practise</a>
</li>
<li class="none">
<a href="howto.html">How to...</a>
</li>
</ul>
<h5>Reference</h5>
<ul>
<li class="none">
<strong>JavaScript API</strong>
</li>
</ul>
<a href="http://maven.apache.org/" title="Built by Maven" id="poweredBy">
<img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
</a>
</div>
</div>
<div id="bodyColumn">
<div id="contentBox">
<div class="section"><h2>JavaScript API Reference</h2><div class="section"><h3>Buffalo</h3><p>Buffalo class is the only one for most cases. </p><div class="section"><h4>Buffalo(gateway, async, events, options) </h4><table class="bodyTable"><tbody><tr class="a"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="b"><td align="left">gateway</td><td align="left">string</td><td align="left">the address of bfapp servlet</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="a"><td align="left">async</td><td align="left">boolean</td><td align="left">if it's a asynchronous call</td><td align="left">false</td><td align="left">true</td></tr><tr class="b"><td align="left">events</td><td align="left">object</td><td align="left">the events handler</td><td align="left">false</td><td align="left">see <a href="howto.html#6"> howto</a></td></tr><tr class="a"><td align="left">options</td><td align="left">object</td><td align="left">other options</td><td align="left">false</td><td align="left">timeout=10000</td></tr></tbody></table><p>This is the constructor for Buffalo, exmple use: </p><div class="source"><pre>var buffalo = new Buffalo("/bfapp/buffalo");
</pre></div><p>To make a synchronized call: </p><div class="source"><pre>var buffalo = new Buffalo("/bfapp/buffalo", false);
</pre></div></div><div class="section"><h4>remoteCall(service, params, callback)</h4><p>remoteCall will make a remote call using the service with params. It will use callback function to handle the result. </p><table class="bodyTable"><tbody><tr class="b"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="a"><td align="left">service</td><td align="left">string</td><td align="left">the service name and method name, format is "serviceName.methodName"</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="b"><td align="left">params</td><td align="left">Array</td><td align="left">the parameter for the remote call</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="a"><td align="left">callback</td><td align="left">function</td><td align="left">the call back function, will take Buffalo.Reply as parameter</td><td align="left">true</td><td align="left">N/A</td></tr></tbody></table><p>Code demo: </p><div class="source"><pre>buffalo.remoteCall("helloService.hello", ['Michael'], function(reply) {
alert(reply.getResult());
})
</pre></div><p>The reply.getResult() will give you exactly the same object model defined in Java in a javascript way. </p><p>Or: </p><div class="source"><pre>buffalo.remoteCall("helloService.hello", ['Michael'], myfunc);
function myfunc(reply) {
alert(reply.getResult());
}
</pre></div></div><div class="section"><h4>setEvents(events)</h4><p>setEvents will customize the event handler for the buffalo instance. </p><table class="bodyTable"><tbody><tr class="b"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="a"><td align="left">events</td><td align="left">object</td><td align="left">the event hanlders</td><td align="left">true</td><td align="left">N/A</td></tr></tbody></table><div class="source"><pre>buffalo.setEvents({onLoading:myloading}})
function myloading(state) {
if (state) {window.status = "loading..."; }
else {window.status = "load completed."; }
}
</pre></div><p>Or you can just like this: </p><div class="source"><pre>buffalo.events["onLoading"] = myloading;
</pre></div></div><div class="section"><h4>bindReply(service, params, elementId)</h4><p>bindReply will make a remote call and bind the result to the element. </p><table class="bodyTable"><tbody><tr class="b"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="a"><td align="left">service</td><td align="left">string</td><td align="left">the service name and method name, format is "serviceName.methodName"</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="b"><td align="left">params</td><td align="left">Array</td><td align="left">the parameter for the remote call</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="a"><td align="left">elementId</td><td align="left">string</td><td align="left">the element which you need bind value to</td><td align="left">true</td><td align="left">N/A</td></tr></tbody></table><p>For example: call the simpleService.provincesNames and bind the result to id=select_provinde form select element</p><div class="source"><pre>buffalo.bindReply("simpleService.provincesNames",[],"select_province");
</pre></div></div><div class="section"><h4>switchView(viewName)</h4><p>switchView will get the <i>viewName</i> 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. </p><table class="bodyTable"><tbody><tr class="b"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="a"><td align="left">viewName</td><td align="left">string</td><td align="left">the view url</td><td align="left">true</td><td align="left">N/A</td></tr></tbody></table><div class="source"><pre>buffalo.switchView("help.html");
</pre></div></div><div class="section"><h4>switchPart(viewName, partId, addToHistory)</h4><p>switchPart will get the <i>viewName</i> page and load the content to element(id=<i>partId</i>), if <i>addToHistory</i> is true, it will add this operation to browser history so that the back/forward button can be used. </p><table class="bodyTable"><tbody><tr class="b"><td align="left"><b>Parameter name</b></td><td align="left"><b>Parameter type</b></td><td align="left"><b>Description</b></td><td align="left"><b>Required?</b></td><td align="left"><b>Default</b></td></tr><tr class="a"><td align="left">viewName</td><td align="left">string</td><td align="left">the view url</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="b"><td align="left">partId</td><td align="left">string</td><td align="left">the div id which will be replaced</td><td align="left">true</td><td align="left">N/A</td></tr><tr class="a"><td align="left">addToHistory</td><td align="left">boolean</td><td align="left">if this operation add to browser history?</td><td align="left">true</td><td align="left">N/A</td></tr></tbody></table></div></div></div>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">©
2004-2006
</div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -