Getting "Unable to find unambiguous method" when calling an enum function from JSF page in EAP 7.x
Environment
Red Hat JBoss Enterprise Application Platform (EAP) 7.x
Issue
Seeing javax.el.ELException while trying to invoke a JSF page example.xhtml. The called function should use an enum as an input parameter but the EL-parser is expecting a string value
SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/example.xhtml]: javax.el.ELException: /example.xhtml @17,90 value="#{foo.getPerson('MY_ENUM').nameS}": Unable to find unambiguous method: class com.example.entity.foo.getPerson(java.lang.String)
Also, the same code works on previous JBoss EAP 6.4.x version.
Resolution
Two Jira's were opened to have this issue fixed, for JBoss EAP 7.1.z and for JBoss EAP 7.2.z. The workaround is:
- Remove the superclass, for example:
package com.entity;
import com.constants.MyEnum;
import java.util.HashMap;
import java.util.Map;
public class MyClass extends MySuperclass {
public MyEntity getPerson(MyEnum enum) { ... }
}
to
package com.entity;
import com.constants.MyEnum;
import java.util.HashMap;
import java.util.Map;
public class MyClass {
public MyEntity getPerson(MyEnum enum) { ... }
}
- Change the parameter to String instead of Enum, for example:
package com.entity;
import com.constants.MyEnum;
import java.util.HashMap;
import java.util.Map;
public class MyClass extends MySuperclass {
public MyEntity getPerson(MyEnum enum) { ... }
}
to
package com.entity;
import com.constants.MyEnum;
import java.util.HashMap;
import java.util.Map;
public class MyClass {
public MyEntity getPerson(String enum) { ... }
}
Root Cause
The Expression Language 3 (EL-API-3) present in EAP 7.x is not able to find the method with an enum as a parameter, however, Expression Language 2.2 (EL-API-2.2) present in EAP 6.4. x is able to identify the method with an enun even though the JSF page passes the parameter as a string value.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.