Announcement Announcement Module
Collapse
No announcement yet.
Error when implementing Enums using Actionscript 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error when implementing Enums using Actionscript 3

    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="com.datacollection.model.Refere nceLookupType")]
    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.ReferenceL ookupType'." 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 'com.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\Ab stractInvoker.as:345]
    at mx.rpc::Responder/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Re sponder.as:68]
    at mx.rpc::AsyncRequest/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\As yncRequest.as:113]
    at NetConnectionMessageResponder/statusHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messag ing\channels\NetConnectionChannel.as:609]
    at mx.messaging::MessageResponder/status()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messag ing\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

  • #2
    Not quite sure, but as far as I know, Java enums get mapped as Strings in AS.

    Means your AS-Enum must look like this (or similar):
    Code:
    public class ReferenceLookupType {
    public static const PATIENT_VISIT_TYPE:String = "PATIENT_VISIT_TYPE"; 
    ...
    see: http://livedocs.adobe.com/blazeds/1/...ze_data_3.html

    Actually, if I got it right, this has nothing to do with Spring Actionscript. But actually (I think) AS3 Commons provides an Enum class. Not sure if you can also use this implementation for BlazeDS mapping...

    Comment


    • #3
      Hi,

      this is indeed not a Spring ActionScript issue, but I'll point out some things we did in order to get typed enums between our server and client.

      Check out this post (http://bugs.adobe.com/jira/browse/BLZ-17) and comments on the Adobe Jira. It contains an EnumProxy class that you need to register as a proxy in BlazeDS. You can do this in a static block as mentioned in the comments, or you can do the registration in your Java Spring context by creating a MethodInvokingFactoryBean, as we did.

      The nice thing is that this will work with the AS3Commons Enum class. The only thing you need to do, is change the value of the EnumProxy.ACTION_SCRIPT_VALUE_NAME variable to "name" instead of "val".

      Then specify a remote class alias for your client enums and you should be good to go.

      regards,
      Christophe

      Comment

      Working...
      X