flex 无法调用 java类
flex无法调用java类我用的MyEclipse6.0+Flex3.0Plugin+SQLServer2005+JDK1.6做个练习mxml代码是从网上粘的,如下:<?...
flex 无法调用 java类 我用的MyEclipse6.0+Flex3.0Plugin+SQLServer2005+JDK1.6做个练习
mxml代码是从网上粘的,如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:RemoteObject id="ud" destination="UserDao" result="onResult(event)" fault="onFault()" />
<mx:DataGrid dataProvider="{users}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="name" />
</mx:columns>
</mx:DataGrid>
<mx:Label id="info" />
<mx:Button label="click" click="clickFun()" />
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
public var users:ArrayCollection=new ArrayCollection();
public function clickFun():void{
ud.getAllUser();
}
public function onResult(event:ResultEvent):void{
users=ArrayCollection(event.result);
info.text="get data successfully";
}
public function onFault():void{
info.text="Error";
}
]]>
</mx:Script>
</mx:Application>
remoting-config.xml文件中也加入了配置,如下
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true" />
</adapters>
<default-channels>
<channel ref="my-amf" />
</default-channels>
<destination id="UserDao">
<properties>
<source>org.rjb.java.UserDao</source>
</properties>
</destination>
</service>
然后运行调试时能出现页面,但是不能获取到数据库中的信息,在UserDao中卡断点发现Flex页面不能执行到UserDao中,这是什么问题,还是需要配置什么。本人是个初学者,还望高手不惜赐教,谢谢!! 展开
mxml代码是从网上粘的,如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:RemoteObject id="ud" destination="UserDao" result="onResult(event)" fault="onFault()" />
<mx:DataGrid dataProvider="{users}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="name" />
</mx:columns>
</mx:DataGrid>
<mx:Label id="info" />
<mx:Button label="click" click="clickFun()" />
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
public var users:ArrayCollection=new ArrayCollection();
public function clickFun():void{
ud.getAllUser();
}
public function onResult(event:ResultEvent):void{
users=ArrayCollection(event.result);
info.text="get data successfully";
}
public function onFault():void{
info.text="Error";
}
]]>
</mx:Script>
</mx:Application>
remoting-config.xml文件中也加入了配置,如下
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true" />
</adapters>
<default-channels>
<channel ref="my-amf" />
</default-channels>
<destination id="UserDao">
<properties>
<source>org.rjb.java.UserDao</source>
</properties>
</destination>
</service>
然后运行调试时能出现页面,但是不能获取到数据库中的信息,在UserDao中卡断点发现Flex页面不能执行到UserDao中,这是什么问题,还是需要配置什么。本人是个初学者,还望高手不惜赐教,谢谢!! 展开
1个回答
展开全部
用下面的方式尝试一下
测试一
<mx:RemoteObject id="ud" destination="UserDao">
<mx:method name="getAllUser" result="onResult(event)" fault="onFault()"/>
</mx:RemoteObject>
测试二
<mx:RemoteObject id="UserDao" destination="UserDao">
<mx:method name="getAllUser" result="onResult(event)" fault="onFault()"/>
</mx:RemoteObject>
确定你呼叫的java端名字正确与否
还有你那script脚本最好写到所有app子组件的最上面。算是规范吧
测试一
<mx:RemoteObject id="ud" destination="UserDao">
<mx:method name="getAllUser" result="onResult(event)" fault="onFault()"/>
</mx:RemoteObject>
测试二
<mx:RemoteObject id="UserDao" destination="UserDao">
<mx:method name="getAllUser" result="onResult(event)" fault="onFault()"/>
</mx:RemoteObject>
确定你呼叫的java端名字正确与否
还有你那script脚本最好写到所有app子组件的最上面。算是规范吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询