---
title: "flex以remoteobject方式调用java方法"
author: "fourfire"
date: "2008-06-23T13:39:04Z"
tags: []
slug: "flex-remoteobject-java"
draft: false
lastmod: "2008-06-23T13:39:04Z"
id: 207083
url: "https://fourfire.iteye.com/blog/207083"
---

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

```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的内容

```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

<?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的，否则传不到后台

```actionscript

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;
		

	}
}

```

搞定！