Flex与SSH集成
2010-
06-
26
11:
00:
36| 分类: flex |举报|
字号 订阅 Flex与SSH集成
1,下载blazeds_bin_3-
0-
0-
544
.zip 包,将其解压 取下blazeds.war包 更改为blazeds.rar ,并解压
2 将上一步解压的web-inf/lib/
下的包复制到工程的lib下
3,将flex文件夹 复制到工程的web-
inf下
4
将classes下的文件复制到工程的src下 5在web.xml中加入 <!-- flex --> <servlet> <servlet-name>flex</servlet-name> <servlet-
class>org.springframework.web.servlet.DispatcherServlet</servlet-
class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/flex-application-config.xml</param-value> </init-param> <load-on-startup>
1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>flex</servlet-name> <url-pattern>/ssh
/*
</url-pattern> </servlet-mapping> <!-- end flex --> 6,在src下建一个flex-application-config.xml文件 加入 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="
http://www.springframework.org/schema/beans
" xmlns:flex="
http://www.springframework.org/schema/flex
" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
"> <flex:message-broker/> <!— 下面是表示 在spring配置文件中配置的bean--> <flex:remoting-destination ref="flowServer"/> </beans> 以下内容 6,加入flex与spring所依赖的包 Flex与SSH集成 - 花落谁家 - zhangcb666的博客 7 编写 java 类 1> 编写类体DeptNode.class package com.svse.entity.bean; import java.util.ArrayList; import java.util.List; /*** * 注: 此类可以不用和Flex映射 ,因为在Flex端,我们不用把Object对象强转为此对象 *
*/
public
class
DeptNode {
private
int
id;
private
String name;
private
DeptNode parent;
private List<DeptNode> children =
null
;
public
DeptNode(){}
public DeptNode(
int
id ,String name){
this.id =
id;
this.name =
name; }
/*
************get and set 省略***************
*/
}
2> 编写接口IflowServer.
class
package com.svse.server; import java.util.List; import com.svse.entity.bean.DeptNode;
public
interface
IFlowServer {
//
得到部门 List<DeptNode> getDeparts(
int
deptId); }
3>
编写实现类 package com.svse.server.impl; import java.util.List; import com.svse.entity.bean.DeptNode; import com.svse.server.IFlowServer;
public
class
FlowServer implements IFlowServer {
//
得到部门
public List<DeptNode> getDeparts(
int
deptId){ List<DeptNode> list =
new ArrayList<DeptNode>
(); DeptNode node =
new
DeptNode(); node.setId(
00
); node.setName(
"
父节点11
"
); node.setChildren(
this.getChild(
3,
"
aa
"
)); list.add(node); DeptNode node2=
new
DeptNode(); node2.setId(
11
); node2.setName(
"
父节点22
"
); node2.setChildren(
this.getChild(
5,
"
bb
"
)); list.add(node2);
return
list; }
private List<DeptNode> getChild(
int
count,String name){ List<DeptNode> list =
new ArrayList<DeptNode>
();
for(
int i =
0; i < count; i++
){ DeptNode node3 =
new
DeptNode(); node3.setId(i); node3.setName(name+
""+
i); list.add(node3); }
return
list; } } }
8
在spring中注入 <bean id=
"
flowServer
"
class=
"
com.svse.server.impl.FlowServer
"/>
注:此处的Id,就是在flex-application-
config.xml中的 <flex:remoting-destination
ref=
"
flowServer
"/>
配置的ref值
9
编写flex代码 <?xml version=
"
1.0
" encoding=
"
utf-8
"?> <mx:Application xmlns:mx=
"
http://www.adobe.com/2006/mxml
" layout=
"
absolute
" creationComplete=
"
init()
"> <mx:Script> <!
[CDATA[ import mx.rpc.remoting.mxml.RemoteObject; import bean.FileAction; import mx.collections.ArrayCollection; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.controls.Alert;
/*
* * 从服务器请示数据 *
*/
function loadDept():
void
{
var remote:RemoteObject =
new
RemoteObject(); remote.destination=
"
flowServer
"
; remote.endpoint=
"
/ssh2-flex/messagebroker/amf
"
; remote.getDeparts(
1
); remote.addEventListener(ResultEvent.RESULT,resultHander1); remote.addEventListener(FaultEvent.FAULT,fault); }
/*
* * 请示成功后,调用的方法 *
*/
function resultHander1(
event:ResultEvent):
void
{
//
在此只用转化为集合对象,不用考虑集合对象中的对象
var list:ArrayCollection =
event.result
as
ArrayCollection;
this.deptList.dataProvider =
list; }
/*
* * 初 始化 *
*/
function init():
void
{
var xmlArray:ArrayCollection =
new
ArrayCollection([ {
"
name
":
"
上海
",
"
selected
":
false,
"
children
":[{
"
name
":
"
黄浦
",
"
selected
":
false
}, {
"
name
":
"
浦东
",
"
selected
":
false
}]}, {
"
name
":
"
北京1
",
"
selected
":
false,
"
children
":
null
} ]);
//
Tree对象默认会取chilren为子节点
deptList.dataProvider =
xmlArray; }
/*
* * 出错后调用的方法 *
*/
function fault(
event:FaultEvent):
void
{ Alert.show(
"
error
"
); }
/*
* * 双击调用的方法 *
*/
function showMsg():
void
{
var st:String = deptList.selectedItem.id +
"
"+
deptList.selectedItem.name; Alert.show(st); } ]]> </mx:Script> <mx:Label /> <mx:HBox> <mx:Button label=
"
加载数据
" click=
"
loadDept()
" fontSize=
"
14
" /> <mx:Tree id=
"
deptList
" labelField=
"
name
" width=
"
200
" height=
"
300
" itemDoubleClick=
"
showMsg()
" /> </mx:HBox> </mx:Application>
注:Java类加也可返回xml格的数据,供flex调用,具体请查看相关文档