[RemoteClass] 在 Flex Actionscript 中如何工作 我可以将其用于自定义数据绑定吗?
Actionscript 支持 BlazeDS 中使用的 [RemoteClass] 元数据标记,为将 AMF 二进制对象从 Java 编组到 BlazeDS 提供数据绑定提示。
例如:
Java: 包装样品;
public class UserInfo
{
private String userName;
public String getUserName()
{
return userName;
}
public void setUserName(String value)
{
userName = value;
}
}
Actionscript:
[Bindable]
[RemoteClass(alias="sample.UserInfo")]
public class UserInfo
{
public var userName:String=”";
}
[RemoteClass] 在 BlazeDS 框架中具体是如何实现的?您能否覆盖该行为并提供一个可以绑定到的自定义数据绑定远程处理框架(例如 JSON 消息传递系统)? Actionscript [Bindable]、[RemoteClass] 类?
Actionscript supports a [RemoteClass] metadata tag that is used in BlazeDS to provide data-binding hints for marshalling AMF binary objects from Java to BlazeDS.
For example:
Java:
package sample;
public class UserInfo
{
private String userName;
public String getUserName()
{
return userName;
}
public void setUserName(String value)
{
userName = value;
}
}
Actionscript:
[Bindable]
[RemoteClass(alias="sample.UserInfo")]
public class UserInfo
{
public var userName:String=”";
}
How exactly is the [RemoteClass] implemented in the BlazeDS framework and could you override that behavior and provide a custom data-binding remoting framework (e.g. a JSON message passing system) that you could bind to the Actionscript [Bindable], [RemoteClass] class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
[RemoteClass(alias="com.example.MyClass")] 是调用 flash.net.registerClassAlias() :
要在运行时访问这些已注册的别名类(以编写自定义 JSON 数据序列化框架),您可以调用:
getClassByAlias(aliasName:String):Class
查找以前通过调用 registerClassAlias() 方法注册了别名的类。
对于从 AS 到 Java 的传出编码,您需要检索别名类名,可以通过调用 flash.utils.describeType() 并在 Actionscript 对象的类上使用“反射”来查询对象的属性、属性和方法。
例如,以下代码段为 ObjectCodec.as 似乎检索别名使用“@”属性:
[RemoteClass(alias="com.example.MyClass")] is a Flex shorthand for calling flash.net.registerClassAlias() :
To access those registered alias classes at runtime (to write a custom JSON data serialization framework) you can call:
getClassByAlias(aliasName:String):Class
Looks up a class that previously had an alias registered through a call to the registerClassAlias() method.
For outgoing encoding from AS to Java you need to retrieve the aliased class name, you can do that by calling flash.utils.describeType() and use "reflection" on your Actionscript object's class to query attributes, properties, methods of the object.
For example the following code snippet for ObjectCodec.as seems to retrieve the alias attribute by using "@":
[RemoteClass]仅在Flex端使用。它真正做的就是调用 flash.net .registerClassAlias() 函数用于设置本地对象和远程类名之间的映射。
[RemoteClass] is only used on the Flex side. All it really does is call the flash.net.registerClassAlias() function to setup a mapping between a local object and a remote class name.
您可以使用 -keep- generated-actionscript 编译器参数来查看生成了哪些代码以及它如何准确工作。
You could use the
-keep-generated-actionscript
compiler argument to see what code is generated and how it works exactly.