flex以remoteobject方式调用java方法

1 install flexbuilder3
2 download ADOBE LIVECYCLE DATA SERVICES SOFTWARE
adobe网站需要注册才可以下载,可以用迅雷下载
[url]
http://trials.adobe.com/pub/esd/trial/livecycle/lcds251-win.exe
[/url]
install
LiveCycle Data Services注册码:
1306-4100-8708-9432-2243-5880
3 download jotm
把lib中的文件放到 tomcat common/lib(6.0 是lib)目录下
在conf/context.xml中加入
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>

4 将LiveCycle 安装目录中的flex.war解压缩,将web.xml中的内容与你的应用中的web.xml合并
其他目录或者文件夹直接放
5 如果你用了log4j,classes下的commons-logging.properties会把log4j关掉,可以删除该文件。
6 修改flex/remoting-config.xml的内容
<destination id="dataService">
     <properties>
          <source>com.longtop.jhcontract.systemmanage.service.DataDictService</source>
     </properties>
	</destination>
	<destination id="approvedService">
     <properties>
          <source>com.longtop.jhcontract.approvedmanage.service.ApprovedService</source>
     </properties>
	</destination>

7 调用xml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
	<![CDATA[
	 import mx.controls.Alert;
	  import mx.utils.ArrayUtil;
	  import com.firebow.model.User;
		private function invokeJava():void
		{
			
			getData.loadAllDataDict();
			
			
		}
		private function invokeJava1():void
		{
			var u:User=new User();
			u.name=("zzp");
			u.id=("8ad45373177d786f01177d89d9f40039");
			approved.loadWaitingWorksCountByUser(u);
			
			
		}
		private function processResult(result:Object):void
            {
                myDG.dataProvider = result;
                Alert.show("invoke end");
            }
            private function processApprovedResult(result:Object):void
            {
               
                Alert.show(String(result));
            }
	]]>
</mx:Script>
	<mx:Button x="21" y="10" label="invoke" click="invokeJava()"/>
	<mx:Button x="100" y="10" label="invokeApproved" click="invokeJava1()"/>
	<mx:RemoteObject id="getData" destination="dataService" result="processResult(event.result)"   fault="Alert.show(event.fault.faultString,'Error')">
		
	</mx:RemoteObject>
	<mx:RemoteObject id="approved" destination="approvedService" result="processApprovedResult(event.result)"   fault="Alert.show(event.fault.faultString,'Error')">
		
	</mx:RemoteObject>
	<mx:DataGrid id="myDG" x="21" y="50">
        <mx:columns>
            <mx:DataGridColumn headerText="名称" dataField="cname"/>
            <mx:DataGridColumn headerText="编码" dataField="code"/>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>


invokeJava是返回集合并显示在datagrid中
invokeJava1传递一个对象到后台,以下是actionscript与后台对应的类,必须包含RemoteClass,属性是public的,否则传不到后台
package com.firebow.model
{
	[RemoteClass(alias="com.longtop.system.model.User")]
	public class User
	{
		public function User()
		{
		}
		public var id:String;
		public var name:String;
		

	}
}

搞定!

你可能感兴趣的:(java,xml,log4j,Flex,actionscript)