How to retrieve the caption of an enumeration in java?

6
I've created a custom java action with 2 parameters: - Any Object [InputObject] - Attribute [MemberVariable] (string) ReturnValue is a string. I want to retrieve the caption of the Any Object/Attribute (enum) in the "en_US" language. I've managed to create the following code but it is not working. Does anyone has a good solution for this? // BEGIN USER CODE IMetaEnumValue test = (IMetaEnumValue)this.InputObject.getValue(getContext(), MemberVariable); return Core.getInternationalizedString("en_US", test.getI18NCaptionKey()); // END USER CODE Now I only get the following exception: Caused by: com.mendix.core.CoreException: java.lang.ClassCastException: java.lang.String cannot be cast to com.mendix.systemwideinterfaces.core.meta.IMetaEnumValue at it.b(SourceFile:167) Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.mendix.systemwideinterfaces.core.meta.IMetaEnumValue
asked
1 answers
7

You can't use getValue() on the IMendixObject as that will directly get you the value, you'll have to use getMember() for this. I'll try to work out a small example.

Edit: code sample:

IMendixObjectMember<?> member = obj.getMember(getContext(), memberName); 
if (member instanceof MendixEnum) {
    MendixEnum mendixEnum = (MendixEnum) member;
    for (IMetaEnumValue value : mendixEnum.getEnumeration().getEnumValues().values())
        if (value.getIdentifier().equals(member.getValue(getContext())))
            System.out.println(Core.getInternationalizedString("en_US", value.getI18NCaptionKey()));
}
answered