mardi 5 mai 2009

GOFJ : Retrieving any bean with any scope

GOFJ ? We'll get back to that.

For now I'll just introduce a way of retrieving your managed bean instance in any place of your project's java classes :

public static Object retrieveManagedBean(String beanName, Class beanClass) {
FacesContext fc = FacesContext.getCurrentInstance();
ValueExpression ve = fc.
getApplication().
getExpressionFactory().
createValueExpression(fc.getELContext(), "#{"+beanName+"}", beanClass);

return ve.getValue(fc.getELContext());
}


Your beanName is specified in either adf-config either faces-config depending on what you've choosed. Also, for backing beans, "backingBeanScope.backing_pageName" is the beanName variable to use since it's the way it's generated by JDeveloper.

That's how it's done, in the Good Old Fashionned Java way.

Aucun commentaire: