Is there a way to cast a result in EL?

Refresh

November 2018

Views

215 time

2

I have JSF page that is trying to call a method in my managed bean, but is throwing an error that I am calling an ambiguous method:

<div class="Container100 MarTop5 #{surveyBean.getBackGroundStyleClass(cc.attrs.multiChoiceItem.answer)}">

The error is:

SEVERE: /resources/component/checkMany2.xhtml: Unable to find unambiguous method: class org.beans.questionnaire.SurveyBean.getBackGroundStyleClass(null)
javax.el.ELException: /resources/component/checkMany2.xhtml: Unable to find unambiguous method: class org.beans.questionnaire.SurveyBean.getBackGroundStyleClass(null)

The problem is that my SurveyBean class has overloaded getBackGroundStyleClass() methods. Consequently, when the cc.attrs.multiChoiceItem.answer is null, it does not know which method to call.

In standard Java, I would be able to cast the answer to the type I want to ensure that Java can find the correct method.

How can I do this in EL? Is it feasible? I've tried:

but that failed miserably:

Failed to parse the expression [#{surveyBean.getBackGroundStyleClass((Answer)cc.attrs.multiChoiceItem.answer)}]

I also tried: #{surveyBean.getBackGroundStyleClass(Answer.class.cast(cc.attrs.multiChoiceItem.answer))}

but that too failed with:

javax.el.ELException: The identifier [class] is not a valid Java identifier as required by section 1.19 of the EL specification (Identifier ::= Java language identifier). This check can be disabled by setting the system property org.apache.el.parser.SKIP_IDENTIFIER_CHECK to true.

Is there some way in EL to cast the argument type?

0 answers