`
JavaCrazyer
  • 浏览: 2990179 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类

Flex4之关于VO对象作为参数传递到服务器端能否转换成JAVA对象的问题解决方案

阅读更多

首先,在FLEX开发过程中,给FLEX客户端设计一个VO(value object)类与JAVA中的实体类相对应,估计大家都做过,不过在作为参数传递到后台时,经常会出这样的错误提示

faultCode:Server.ResourceUnavailable faultString:'
Cannot invoke method 'merge'.' faultDetail:
'The expected argument types are (com.card.entity.Users)
 but the supplied types were (flex.messaging.io.amf.ASObject) 
and converted to (null).'

  比如你是这么传递客户端的对象值

public function dodeletes(u:Users):void{
   service.deletes(u);
  }

 服务器端呢,你肯定有对应的

public boolean deletes(Users persistentInstance) {
  if (null != persistentInstance) {
   getSession().delete(persistentInstance);
   return true;
  } else {
   return false;
  }

 }

由于一个是FLEX客户端的VO,一个是JAVA类,所以要转换肯定需要一些设置,关键就是要在VO上加上一些元数据、

package vo
{
	import mx.rpc.remoting.RemoteObject;

	[Bindable]
	[RemoteClass(alias="com.card.entity.Users")]
	public class Users
	{
		public var id:int;
		public var username:String;
		public var email:String;
		public var phonenum:String;
		public var detail:String;
		
	}
}

 

看见了没,
[RemoteClass(alias="com.card.entity.Users")]
这个起了关键作用,设置好了之后就不会出错了

2
0
分享到:
评论
2 楼 shiguang0122 2012-09-20  


谢了。
我的就是这个错误,按照网上的方法,检查配置,类名啥的,N遍也没有效果。

结果,终于搜到你这。

知道了映射转换对象的关键,于是,重写了 Bindable 和 Remoteclass ,行了。。。

无语,早知道那会编写as类的时候就复制了,我背写的,也不知道单词哪里写错了,悲剧了三个钟头啊。。。啊阿拉啊啊啊。。。
1 楼 Jeaneler 2011-12-09  
不知道flex3可不可以也这样  

相关推荐

Global site tag (gtag.js) - Google Analytics