ITeye博客

flex以remoteobject方式调用java方法

fourfire · 2008-06-23 13:39 · flex · Markdown

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中加入


<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;
		

	}
}

搞定!

评论(3)

  1. #3 楼 · hbing110 · 2009-04-02 17:14

    这样会让我们把很多在前台处理的东西放到后台java这里来 谢谢./

  2. #2 楼 · fourfire · 2008-06-24 09:55

    配置方法类似,调用方法相同

  3. #1 楼 · yexin218 · 2008-06-23 18:01

    我喜欢用blazeds调用java

评论功能维护中,当前仅展示历史评论。