0

I am trying to get enum value in JSP page but getting exception

org.apache.jasper.JasperException: javax.el.MethodNotFoundException: Method not found: class org.hibernate.collection.internal.PersistentSet.getFieldType()

package com.nfdil.loyalty.enums;

public enum FieldTypeEnum {
    TEXT_BOX("TEXT_BOX"), CHECK_BOX("CHECK_BOX");

    private String fieldType;

    private FieldTypeEnum(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getFieldType() {
        return fieldType;
    }
}

Code in JSP page :

<c:when test="${programFuncFileds.getFieldType() == FieldTypeEnum.TEXT_BOX.getFiledType()}">                                                
</c:when>

I don't want to use any hard code.

Got reference form here Access Enum value using EL with JSTL

but my problem is not solved.

Community
  • 1
  • 1
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
  • 1
    It seems like the programFuncFileds object has no getFieldType method. You should check, if it´s the correct object. – Franz Deschler Feb 02 '17 at 07:11
  • You could reduce the code of your enum. The fieldType parameter is not necessary because the fieldType string is the same as the constant itself. Simply define an Enum without any fields and methods. To get the String of an Enum constant, you can use TEXT_BOX.name(). – Franz Deschler Feb 02 '17 at 07:13

1 Answers1

2

Solution is :

<c:set var="filedTypeEnum" value="<%=FieldTypeEnum.TEXT_BOX.getFieldType()%>" />

<c:when test="${programFuncFields.getFieldType() == filedTypeEnum}">
</c:when>
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94