You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by zqzuk <zi...@hotmail.com> on 2008/04/13 19:14:08 UTC
how to access registered bean in code
Hi, I need to access an "application" scoped bean defined in faces-config. I
digged in the forum and did found some answers to tihs, e.g.,
"FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance
(), "myBean1");",
However this is deprecated version and when I am looking at JSF 1.2
documentation, I cannot figure out what is the equivalent way to do this...
Please could you give me some hints, many thanks!
--
View this message in context: http://www.nabble.com/how-to-access-registered-bean-in-code-tp16661140p16661140.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: how to access registered bean in code
Posted by zqzuk <zi...@hotmail.com>.
Thanks so much! It works perfect!
--
View this message in context: http://www.nabble.com/how-to-access-registered-bean-in-code-tp16661140p16676279.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: how to access registered bean in code
Posted by Hazem Saleh <ha...@gmail.com>.
Hi mate,
Use this for JSF 1.2 :-
FacesContext context = FacesContext.getCurrentInstance();
ELResolver resolver = context.getApplication().getELResolver();
MyBean myBean1 = (MyBean)
resolver.getValue(context.getELContext(), null, "myBean1");
On Sun, Apr 13, 2008 at 7:14 PM, zqzuk <zi...@hotmail.com> wrote:
>
> Hi, I need to access an "application" scoped bean defined in faces-config.
> I
> digged in the forum and did found some answers to tihs, e.g.,
>
> "FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance
> (), "myBean1");",
>
> However this is deprecated version and when I am looking at JSF 1.2
> documentation, I cannot figure out what is the equivalent way to do
> this...
>
> Please could you give me some hints, many thanks!
>
>
> --
> View this message in context:
> http://www.nabble.com/how-to-access-registered-bean-in-code-tp16661140p16661140.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Hazem Ahmed Saleh Ahmed
http://www.jroller.com/page/HazemBlog
RE: how to access registered bean in code
Posted by Mark Millman <ma...@mizar.com>.
Try this, it should work for any Expression but we just use it to fetch
managed bean instances.
/**
* @param managedBeanName
* @return the current instance of the managed bean
* @see FacesContext#getELContext
* @see ELContext#getELResolver
* @see ELResolver
*/
public static Object getManagedBeanInstance(String managedBeanName) {
Object object = null;
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
ELContext ec = context.getELContext();
if (ec != null) {
ELResolver er = ec.getELResolver();
object = er.getValue(ec, null, managedBeanName);
}
}
return object;
}
mark.millman@mizar.com | www.mizar.com | (360) 945-2643
-----Original Message-----
From: zqzuk [mailto:ziqi.zhang@hotmail.com]
Sent: Sunday, April 13, 2008 10:14 AM
To: users@myfaces.apache.org
Subject: how to access registered bean in code
Hi, I need to access an "application" scoped bean defined in faces-config. I
digged in the forum and did found some answers to tihs, e.g.,
"FacesContext.getCurrentInstance().getApplication().getVariableResolver().re
solveVariable(FacesContext.getCurrentInstance
(), "myBean1");",
However this is deprecated version and when I am looking at JSF 1.2
documentation, I cannot figure out what is the equivalent way to do this...
Please could you give me some hints, many thanks!
--
View this message in context:
http://www.nabble.com/how-to-access-registered-bean-in-code-tp16661140p16661
140.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.