Flex与SSH集成

时间:2021-08-01 19:34:28
Flex与SSH集成  

-- ::|  分类: flex |举报|字号 订阅
Flex与SSH集成
,下载blazeds_bin_3---.zip 包,将其解压 取下blazeds.war包 更改为blazeds.rar ,并解压
将上一步解压的web-inf/lib/下的包复制到工程的lib下
,将flex文件夹 复制到工程的web-inf下
将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></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 省略****************/ }
> 编写接口IflowServer.class
package com.svse.server; import java.util.List;
import com.svse.entity.bean.DeptNode; public interface IFlowServer {
//得到部门
List<DeptNode> getDeparts(int deptId);
} > 编写实现类
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();
node.setName("父节点11");
node.setChildren(this.getChild(, "aa")); list.add(node); DeptNode node2= new DeptNode();
node2.setId();
node2.setName("父节点22");
node2.setChildren(this.getChild(, "bb")); list.add(node2); return list;
} private List<DeptNode> getChild(int count,String name){
List<DeptNode> list = new ArrayList<DeptNode>();
for(int i = ; i < count; i++){
DeptNode node3 = new DeptNode();
node3.setId(i);
node3.setName(name+""+i);
list.add(node3);
}
return list;
} }
} 在spring中注入
<bean id="flowServer" class="com.svse.server.impl.FlowServer"/>
注:此处的Id,就是在flex-application-config.xml中的
<flex:remoting-destination ref="flowServer"/>配置的ref值 编写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();
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="" />
<mx:Tree id="deptList" labelField="name" width="" height="" itemDoubleClick="showMsg()" />
</mx:HBox>
</mx:Application>
注:Java类加也可返回xml格的数据,供flex调用,具体请查看相关文档