/**
* 根据 faces-confis.xml 中的 Managed Bean
的名称,来获取当前 FacesContext 中的相应 Managed Bean
*
* @param beanName El表达式 ,例如: #{backingBean}
* @return the managed bean associated with the bean name
*/
public static Object getManagedBean(String beanName) {
return getValueBinding(beanName).
getValue(FacesContext.getCurrentInstance());
return getApplication().createValueBinding(el);
ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
.getFactory(FactoryFinder.APPLICATION_FACTORY);
return appFactory.getApplication();
通过Application创建一个ValueBinding对象,这个对象能够和资源文件联系起来,通过它的getValue()方法反转得到一个Java Object实例。我们在引用时再转换成我们需要的类型即可。
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{SoCreator.conumber}");
vb.setValue(context,co);
* 根据 faces-confis.xml 中的 Managed Bean
的名称,来获取当前 FacesContext 中的相应 Managed Bean
*
* @param beanName El表达式 ,例如: #{backingBean}
* @return the managed bean associated with the bean name
*/
public static Object getManagedBean(String beanName) {
return getValueBinding(beanName).
getValue(FacesContext.getCurrentInstance());
}
private static ValueBinding getValueBinding(String el) {
return getApplication().createValueBinding(el);
}
private static Application getApplication() {
ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
.getFactory(FactoryFinder.APPLICATION_FACTORY);
return appFactory.getApplication();
}
通过Application创建一个ValueBinding对象,这个对象能够和资源文件联系起来,通过它的getValue()方法反转得到一个Java Object实例。我们在引用时再转换成我们需要的类型即可。
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{SoCreator.conumber}");
vb.setValue(context,co);