spring with buffalo

AJAX:Asynchronous JavaScript and XML

(1)buffalo.xml:配置与spring service对应关系

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<bean name="buffaloConfigBean"
		class="net.buffalo.service.BuffaloServiceConfigurer">
		<property name="services">
			<map>
				<entry key="helloService">
					<ref bean="helloService" />
				</entry>
		
			</map>
		</property>
	</bean>
</beans>


(2)web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Buffalo Example Application</display-name>
<servlet>
    <servlet-name>bfapp</servlet-name>
    <servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>bfapp</servlet-name>
    <url-pattern>/bfapp/*</url-pattern>
</servlet-mapping>
</web-app>


(3)applicationContext.xml:引入关联配置

<import resource="buffalo.xml" />


(4)调用
<script language="javascript">

   var END_POINT="/bfapp";
   var buffalo = new Buffalo(END_POINT,false);//同步调用

function hello() {
    var p1 = $("myname").value;
    buffalo.remoteCall("helloService.hello",[p1], function(reply) {
        alert(reply.getResult());
    });
}
</script>



(5)Customize events

var buffalo = new Buffalo(endpoint, async, {onLoading: yourLoadingFunction, onError: yourErrorHanlder ,onFinish:...})
//或者
buffaloInstance.events["onLoading"] = function(state) {
        if (state) { //displaying message
            window.status  =   " Loading ..." ;
       }else    {
            window.status  =   " Loading complete ";
       }
}


(6)Data binding:bind the javascript object value to html elements

buffalo.bindReply(service, params, elementId);
//或者
Buffalo.Bind.bind(elementId, bindValue). 


(7)关于提示信息的相关处理

a.隐藏掉"buffalo loading..."
   打开buffalo.js,找到response函数的定义,this.events["onLoading"](false);

b.错误提示
   打开buffalo.js,找到onError事件的定义,就是"onError: Buffalo.Default.showError,alertError: function(errorStr) {
alert("抱歉,可能是系统正忙,请稍候再试。");
},

然后把onError定义改为"onError: Buffalo.Default.alertError

c.不改原代码
buffalo.events["onLoading"]=yourunctionname;
buffalo.events["onError"]=yourAnotherFunctionName;

(8)浏览器前进/后退

这个特性需要buffalo-blank.html文件。下载的二进制包中包含此文件。

<iframe src="buffalo-blank.html"id="buffalo-view-history-iframe" width="0" height="0"style="display:none;"></iframe>

    当你想切换视图时,使用buffalo.switchView(viewName)方法,Buffalo将自动记住历史。如果在一些视图中不需要此特征,可以使用buffalo.switchPart(...)方法排除。

你可能感兴趣的:(JavaScript,java,spring,Web,xml)