使用 Actionscript 3 实现枚举时出错

发布于 2024-09-24 11:14:11 字数 3244 浏览 3 评论 0原文

我们的项目是 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 中正确实现枚举吗方式。

谢谢哈里什

Ours is a Flex/Parsley/Blazeds/Spring project & I'm trying to implement java Enums in Actionscript3 and all I have to do is to send the Enum value to Spring service method.

The Java Enum Code (this is generated from 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 is:

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;
        }
    }
}

In the mxml code:

[Bindable]
            private var refLookupType:ReferenceLookupType = ReferenceLookupType.LIPID_PREFILLED_CODE;


dispatcher(new ReferenceDataMessage(refLookupType, "RefData"));

The Error I'm getting is:

"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]

Can you please help in what I'm missing here and on how to implement Enums in Actionscript the right way.

Thanks

Harish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-10-01 11:14:11

枚举在 Flex/BlazeDS 中不能立即使用。你必须施展一点定制魔法。

到目前为止,该主题的权威来源是 Farrata Systems 的这篇博客文章

主要问题是通过线路发送的任何对象都必须具有无参数构造函数。枚举打破了这个规则。

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

FWIW,我还建议看看 DTO2FX 来自同一团队。他们将正确生成 Java 枚举的动作脚本版本自动,以确保它们可以通过网络顺利发送。

Enums don't work out-of-the-box in Flex/BlazeDS. You have to do a little custom magic.

The authoritative source on the topic is by far this blog entry from Farrata Systems.

The main problem is that any object that is being sent across the wire must have a paramaterless constructor. Enums break this rule.

So, you need to use a custom serializer / deserializer for Enums.

FWIW, I'd also suggest taking a look at DTO2FX from the same crew. They will generate the actionscript versions of your Java Enums correctly & automatically, to ensure that they can be sent across the wire without hiccups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文