views:

46

answers:

1

Hi All

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

+1  A: 

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.

Marty Pitt
Thanks for your input on this...I came across this post earlier but was thinking there should be a simpler and easier way to do it......I will try that and let know..Thanks again
Harish
Unfortunately, this is the easiest way I know of.
Marty Pitt