我们是一个 Flex/Parsley/Blazeds/Spring 项目,我正在尝试在 Actionscript3 中实现 java Enums,我所要做的就是将 Enum 值发送到 Spring 服务方法。
Java 枚举代码(这是从 XSD 生成的)
public enum ReferenceLookupType {
PATIENT_VISIT_TYPE("PATIENT_VISIT_TYPE"), PATIENT_STATUS(
"PATIENT_STATUS"), PATIENT_VISIT_INVALID_REASON(
"PATIENT_VISIT_INVALID_REASON"), LIPID_PREFILLED_CODE(
"LIPID_PREFILLED_CODE");
private final String value;
private ReferenceLookupType(String value) {
this.value = value;
}
public String toString() {
return value;
}
public static ReferenceLookupType convert(String value) {
for (ReferenceLookupType inst : values()) {
if (inst.toString().equals(value)) {
return inst;
}
}
return null;
}
}
Actionscript 枚举是:
package {
[Bindable]
[RemoteClass(alias="gov.hhs.cms.ehrds.datacollection.model.ReferenceLookupType")]
public final class ReferenceLookupType {
public static const PATIENT_VISIT_TYPE:ReferenceLookupType = new ReferenceLookupType("PATIENT_VISIT_TYPE");
public static const PATIENT_STATUS:ReferenceLookupType = new ReferenceLookupType("PATIENT_STATUS");
public static const PATIENT_VISIT_INVALID_REASON:ReferenceLookupType = new ReferenceLookupType("PATIENT_VISIT_INVALID_REASON");
public static const LIPID_PREFILLED_CODE:ReferenceLookupType = new ReferenceLookupType("LIPID_PREFILLED_CODE");
private var _value:String;
public function ReferenceLookupType(value:String) : void
{
_value = value;
}
public function toString():String
{
return _value;
}
}
}
在 mxml 代码中:
[Bindable]
private var refLookupType:ReferenceLookupType = ReferenceLookupType.LIPID_PREFILLED_CODE;
dispatcher(new ReferenceDataMessage(refLookupType, "RefData"));
我遇到的错误是:
"Unable to create a new instance of type 'gov.hhs.cms.ehrds.datacollection.model.ReferenceLookupType'." faultCode="Client.Message.Encoding" faultDetail="Types cannot be instantiated without a public, no arguments constructor."
[RPC Fault faultString="Unable to create a new instance of type 'gov.hhs.cms.ehrds.datacollection.model.ReferenceLookupType'." faultCode="Client.Message.Encoding" faultDetail="Types cannot be instantiated without a public, no arguments constructor."]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:345]
at mx.rpc::Responder/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
at mx.rpc::AsyncRequest/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
at NetConnectionMessageResponder/statusHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:609]
at mx.messaging::MessageResponder/status()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:264]
您能否帮助我解决这里缺少的内容以及如何在 Actionscript 中以正确的方式实现枚举。
谢谢
哈里什
最佳答案
枚举在 Flex/BlazeDS 中不能直接使用。您必须施展一些自定义魔法。
到目前为止,该主题的权威来源是 this blog entry来自 Farrata Systems。
主要问题是通过线路发送的任何对象都必须具有无参数构造函数。枚举打破了这个规则。
因此,您需要为枚举使用自定义序列化器/反序列化器。
FWIW,我还建议看看 DTO2FX来自同一个船员。它们将正确自动生成 Java 枚举的 ActionScript 版本,以确保它们可以顺利地通过网络发送。
关于java - 使用 Actionscript 3 实现枚举时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3769966/