预览文章: Buffalo之 bind,reply,ajax,view,form应用(二)
http://liuzidong.iteye.com/blog/629898
四 与spring集成
1 spring版本为:spring-1.2.3.jar
web.xml配置代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>bfapp</servlet-name>
<servlet-class>
net.buffalo.web.servlet.ApplicationServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bfapp</servlet-name>
<url-pattern>/bfapp/*</url-pattern>
</servlet-mapping>
applicationContext.xml的配置代码:
<bean name="userService" class="net.buffalo.service.UserService"></bean>
<bean name="buffaloConfigBean" class="net.buffalo.service.BuffaloServiceConfigurer">
<property name="services">
<map>
<entry key="springUserService">
<ref bean="userService"/>
</entry>
//配置更多的代理...
</map>
</property>
</bean>
注意事项:
1 这里的bfapp启动时间要大于spring时间,要保证spring优先于Buffalo加载.
否则就报如下错误,找不到springUserService这个服务.
net.buffalo.service.NoSuchServiceException: springUserService at net.buffalo.service.DefaultServiceRepository.get(DefaultServiceRepository.java:87) at net.buffalo.service.BuffaloWorker.processRequest(BuffaloWorker.java:60) at net.buffalo.web.servlet.ApplicationServlet.doRequest(ApplicationServlet.java:119) at net.buffalo.web.servlet.ApplicationServlet.doPost(ApplicationServlet.java:91)
2 当把org.springframework.web.context.ContextLoaderServlet
换成:
org.springframework.web.context.ContextLoaderListener后,控制台报如下错误
java.lang.ClassCastException: org.springframework.web.context.ContextLoaderListener
在spring-1.2.3,spring-2.5.5, spring-framework-3.0.0.M4版本下还是这个错误,不过使用: org.springframework.web.context.ContextLoaderServlet在这三个版本下测试正常.
3集成spring后, userService类中的调用方法不能在获取到容器的对象,如这样的代码:
RequestContext.getContext().getHttpSession();类似的调用都会报错,spring提供了这个服务类的所有代理.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.FatalBeanException: Could not instantiate class [net.buffalo.service.UserService]; constructor threw exception; nested exception is java.lang.NullPointerException: null
org.springframework.beans.FatalBeanException: Could not instantiate class [net.buffalo.service.UserService]; constructor threw exception; nested exception is java.lang.NullPointerException: null
java.lang.NullPointerException at net.buffalo.request.RequestContext.getHttpSession(RequestContext.java:105)...
五 Buffalo提供的常用JS函数
1 获取元素的Y坐标
function getElementY(element){
var targetTop = 0;
if (element.offsetParent) {
while (element.offsetParent) {
targetTop += element.offsetTop;
element = element.offsetParent;
}
} else if (element.y) {
targetTop += element.y;
}
return targetTop;
}
2 获取元素的X坐标
function getElementX(element){
var targetLeft = 0;
if (element.offsetParent) {
while (element.offsetParent) {
targetLeft += element.offsetLeft;
element = element.offsetParent;
}
} else if (element.y) {
targetLeft += element.x;
}
return targetLeft;
}
3 绑定元素值
<INPUT TYPE="checkbox" NAME="" id="testChk">
<INPUT TYPE="button" value="Bind Checkbox" onclick="bindChkbox()">
function bindChkbox() {
//点击后只能是选中状态
Buffalo.bind("testChk", "yes");
//Buffalo.bind("testChk", "no");
}
4 遍历对象值
function openObj(obj) {
var tmp = obj+"{";
for (var x in obj) {
tmp += x + "=" + obj[x]+";";
}
tmp += "}";
return tmp;
}
分享到:
相关推荐
buffalo1.2ajax框架应用演示例子 buffalo1.2下载地址: http://www.codechina.net/resource/html/2005-12/06/119641.html
国人开发的AJAX应用框架 AJAX是开发基于web的rich client的一种方式,Buffalo则是实现AJAX的一个框架。Buffalo中定义了Web远程调用的传输基础,并且将远程调用对象完整的序列化到了本地,成为可以被JavaScript编程...
Buffalo则是实现AJAX的一个框架。Buffalo中定义了Web远程调用的传输基础,并且将远程调用对象完整的序列化到了本地,成为可以被JavaScript编程触及的对象。Buffalo中的重要组件-BuffaloBinding,提供了将JavaScript...
buffalo应用实例,列举了buffalo应用中的各种技巧实例 格式rar
基于Ajax的buffalo技术的helloword和三级联动菜单 包含入门模块:helloword、延伸模块:三级联动菜单 项目已包含所有文件,只需导入myeclipse运行即可。 开发环境:myeclipse6.0、jdk1.5、tomcat5.0 说明:连数据库...
国产Ajax框架 Buffalo
Buffalo应用文档,讲述了buffalo应用中的一些技巧,值得一看 格式pdf
国产Ajax框架 Buffalo.7z
基于Java的国产Ajax框架 Buffalo.zip
基于java的国产Ajax框架 Buffalo.zip
java源码:国产Ajax框架 Buffalo.rar
buffalo2.0.jar,ajax使用buffalo框架!
buffalo-l 包buffalo-sc包
Buffalo是一个J2EE轻量级AJAX框架,也是国内著名的开源项目。它与DWR 和JSON-RPC一样,着眼于Web远程调用(Web Remoting),其简洁而实用的特性一直以来深受开发者喜爱。 Buffalo2.0最大的特点在于其性能的提升,还有...
buffalo 一款js框架 类似于ajax 方便实用
基于Java的实例源码-国产Ajax框架 Buffalo.zip
buffalo.jar包与buffalo.js
基于java的开发源码-国产Ajax框架 Buffalo.zip
国产Ajax框架 Buffalo源码
insightface 需要