使用Actionscript 3实现枚举时出错

时间:2010-09-22 13:56:56

标签: java flex actionscript-3 enums

我们的是Flex / Parsley / Blazeds / Spring项目&我正在尝试在Actionscript3中实现java Enums,我所要做的就是将Enum值发送给Spring服务方法。

Java Enum Code(这是从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;
    }
}

The Actionscript Enum是:

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中实现Enums。

由于

哈里什

1 个答案:

答案 0 :(得分:4)

Enums在Flex / BlazeDS中不能开箱即用。你必须做一点自定义魔术。

关于该主题的权威来源是Farrata Systems迄今为止this blog entry

主要问题是通过线路发送的任何对象都必须具有无参数构造函数。 Enums违反了这条规则。

因此,您需要为Enums使用自定义序列化器/反序列化器。

FWIW,我还建议你看看同一个工作人员的DTO2FX。他们将正确生成Java Enums的actionscript版本。自动,以确保它们可以通过电线发送而不会打嗝。