我有JSF页面试图在我的托管bean中调用一个方法,但是抛出一个我称之为模糊方法的错误:
<div class="Container100 MarTop5 #{surveyBean.getBackGroundStyleClass(cc.attrs.multiChoiceItem.answer)}">
错误是:
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)
问题是我的SurveyBean类有重载getBackGroundStyleClass()
方法。因此,当cc.attrs.multiChoiceItem.answer
为null时,它不知道要调用哪个方法。
在标准Java中,我可以将答案转换为我想要的类型,以确保Java可以找到正确的方法。
我怎样才能在EL中这样做?这可行吗?我试过了:
但是那次失败了:
Failed to parse the expression [#{surveyBean.getBackGroundStyleClass((Answer)cc.attrs.multiChoiceItem.answer)}]
我也尝试过: #{surveyBean.getBackGroundStyleClass(Answer.class.cast(cc.attrs.multiChoiceItem.answer))}
但是也失败了:
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.
EL中是否有某种方式来转换参数类型?