Jump to content

Enums as fields


rfcmahesh

Recommended Posts

Hello,

 I am using JRBeanCollectionDataSource as my data source. One of the fields in the bean is an enum type. When I use that property as a field in the report, I get class cast saying Enum cannot be converted to String. I even tried doing $F{enumProperty}.toString(), but it still complains. Can someone please give some pointers.

Thanks,

 

Link to comment
Share on other sites

Figured a way to solve the issue.

Make the field which corresponds to enumType as Object and the textField expression as String. It works for me.


Code:
effectiveType is an enum type in my bean.<field name="effectiveType" class="java.lang.Object"/>The text field expression is<textFieldExpression   class="java.lang.String"><![CDATA[""+$F{effectiveType}]]></textFieldExpression>
  • Like 1
Link to comment
Share on other sites

  • 10 years later...

public enum EnumTest {

    TestValue1(1, "Value for displayed 1"), 
    TestValue2(2, "Value for displayed 2"),
    
    private Integer  id;
    private String description;
    

   public String getDescription() {
         return description;

    }

}


you can call method your enum for example : 

$F{fieldForEnumTest}.getDescription();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...