Jsf 2 如何使用表达式语言调用托管bean方法
我正在开发一个实用程序类,使用它我们需要调用一个在EL表达式中定义的托管bean方法。是否有类似如何使用EL表达式调用托管bean方法的示例 这里我不知道托管bean的类型。但我知道我的表情。因此,我无法向特定的托管bean键入cast 表达式是:Jsf 2 如何使用表达式语言调用托管bean方法,jsf-2,Jsf 2,我正在开发一个实用程序类,使用它我们需要调用一个在EL表达式中定义的托管bean方法。是否有类似如何使用EL表达式调用托管bean方法的示例 这里我不知道托管bean的类型。但我知道我的表情。因此,我无法向特定的托管bean键入cast 表达式是:{phaseListenerBean.compListener} 我的代码如何调用phaseListenerBean上的compListener方法? 我的实用课。它在Jar文件中可用 `前期公共无效(阶段事件事件){ if(PhaseId.RENDE
{phaseListenerBean.compListener}
我的代码如何调用phaseListenerBean
上的compListener
方法?
我的实用课。它在Jar文件中可用
`前期公共无效(阶段事件事件){
if(PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())){
SystemListLoaderHelper.populateSelectOneValidValues()
//CallModuleSpecificationServiceCalls();
}
}`您可以尝试使用Faces上下文调用bean,例如,如果您想要bean,可以使用:
FacesContext facesContext = FacesContext.getCurrentInstance();
Object o = facesContext.getApplication().evaluateExpressionGet(facesContext,
"#{phaseListenerBean}", Object.class);
然后使用反射调用该方法,或者,可以使用表达式调用该方法,如下所示:
FacesContext fc = getContext();
ExpressionFactory factory = getExpressionFactory();
methodExpression = factory.createMethodExpression(
fc.getELContext(), "#{phaseListenerBean.compListener}",
Void.class, (Class<?>) null);
methodExpression.invoke(fc.getELContext(), null);
FacesContext fc=getContext();
ExpressionFactory=getExpressionFactory();
methodExpression=factory.createMethodExpression(
fc.getELContext(),“#{phaseListenerBean.compListener}”,
Void.class,(class)null);
调用(fc.getELContext(),null);
请显示“compListener”和实用程序类的一些代码。对不起,我的英语不好
干杯为您的实用程序类显示一些代码。传递null的intead我传递了类[]{},如下所示
FacesContext fc = getContext();
ExpressionFactory factory = getExpressionFactory();
methodExpression = factory.createMethodExpression(
fc.getELContext(), "#{phaseListenerBean.compListener}",
Void.class, (Class<?>) null);
methodExpression.invoke(fc.getELContext(), null);