Loop through the Mbeans in Session Scope [message #475547] |
Tue, 04 March 2008 09:12  |
Eclipse User |
|
|
|
Originally posted by: reto.huber.alabus.com
Hi
I would like to loop through all registred MBeans (in session scope) in the
current session. Is there an easy way to do this? I don't have the name of
each Mbean to call them.
Regards,
Reto
|
|
|
|
|
|
|
|
Re: Loop through the Mbeans in Session Scope [message #475607 is a reply to message #475596] |
Thu, 13 March 2008 13:09  |
Eclipse User |
|
|
|
Originally posted by: reto.huber.alabus.com
Thank you for your hints. I'm looping now through my session objects and
search for this one I need.
Map sessionMap = context.getExternalContext().getSessionMap();
Iterator it = sessionMap.entrySet().iterator();
while (it.hasNext()) {
Object obj = ((Entry)it.next()).getValue();
if(obj instanceof AesWebBoBean) {
// do something
}
}
>> But I am not sure whether all registered MBeans with session scope are
>> created
>> at e.g. session start.
>
> None of them are created at session start. Managed beans are created when
> they
> are first referenced in an expression.
that's correct.
kindest regards,
Reto
|
|
|
Re: Loop through the Mbeans in Session Scope [message #617144 is a reply to message #475547] |
Tue, 04 March 2008 09:55  |
Eclipse User |
|
|
|
On 3/4/2008 9:12 AM, Reto Huber wrote:
> Hi
>
> I would like to loop through all registred MBeans (in session scope) in the
> current session. Is there an easy way to do this? I don't have the name of
> each Mbean to call them.
At design time or runtime?
|
|
|
|
Re: Loop through the Mbeans in Session Scope [message #617455 is a reply to message #475549] |
Tue, 04 March 2008 10:45  |
Eclipse User |
|
|
|
On 3/4/2008 10:22 AM, Reto Huber wrote:
>> "Yury Kats" <ykats@us.ibm.com> wrote in message
>> news:fqjnqk$vlf$1@build.eclipse.org...
>> On 3/4/2008 9:12 AM, Reto Huber wrote:
>>> Hi
>>>
>>> I would like to loop through all registred MBeans (in session scope) in
>>> the
>>> current session. Is there an easy way to do this? I don't have the name
>>> of
>>> each Mbean to call them.
>> At design time or runtime?
>
> at runtime
While this a wrong forum for a runtime JSF question (better ask in Sun's or MyFaces,
depending on what implementation you use), the short answer is that there is no
public API to get a list of managed beans. JSF implementaion parses all available faces-config
files at startup, so you may take a look at how exactly that is done and where the information
is stored in the implementation you are using. Then either access the list if implementaion allows
it or parse config files yourself.
Why?
|
|
|
Re: Loop through the Mbeans in Session Scope [message #617465 is a reply to message #475547] |
Wed, 05 March 2008 04:59  |
Eclipse User |
|
|
|
Hi Reto,
you can find the MBeans in the session context, where the key is the MBean name
from faces-config.xml:
HttpSession session = (HttpSession)
FacesContext.getCurrentInstance().getExternalContext().getSe ssion(false);
session.getAttribute ("myManagedBeanName")
But I am not sure whether all registered MBeans with session scope are created
at e.g. session start.
Best regards
Wolfgang
Reto Huber schrieb:
> Hi
>
> I would like to loop through all registred MBeans (in session scope) in the
> current session. Is there an easy way to do this? I don't have the name of
> each Mbean to call them.
>
> Regards,
> Reto
>
>
|
|
|
Re: Loop through the Mbeans in Session Scope [message #617468 is a reply to message #475595] |
Wed, 05 March 2008 08:22  |
Eclipse User |
|
|
|
On 3/5/2008 4:59 AM, Wolfgang Knauf wrote:
> Hi Reto,
>
> you can find the MBeans in the session context, where the key is the MBean name
> from faces-config.xml:
Yes, but OP said he didn't know the names of the beans.
> HttpSession session = (HttpSession)
> FacesContext.getCurrentInstance().getExternalContext().getSe ssion(false);
> session.getAttribute ("myManagedBeanName")
This could thrown an NPE if getSession(false) didn't return a session.
A better way to access a managed bean (knowing its name) is to use JSF API
for ValueBindings (JSF 1.1) or ValueExpressions (JSF 1.2).
> But I am not sure whether all registered MBeans with session scope are created
> at e.g. session start.
None of them are created at session start. Managed beans are created when they
are first referenced in an expression.
>
> Best regards
>
> Wolfgang
>
> Reto Huber schrieb:
>> Hi
>>
>> I would like to loop through all registred MBeans (in session scope) in the
>> current session. Is there an easy way to do this? I don't have the name of
>> each Mbean to call them.
>>
>> Regards,
>> Reto
>>
>>
|
|
|
Re: Loop through the Mbeans in Session Scope [message #617499 is a reply to message #475596] |
Thu, 13 March 2008 13:09  |
Eclipse User |
|
|
|
Originally posted by: reto.huber.alabus.com
Thank you for your hints. I'm looping now through my session objects and
search for this one I need.
Map sessionMap = context.getExternalContext().getSessionMap();
Iterator it = sessionMap.entrySet().iterator();
while (it.hasNext()) {
Object obj = ((Entry)it.next()).getValue();
if(obj instanceof AesWebBoBean) {
// do something
}
}
>> But I am not sure whether all registered MBeans with session scope are
>> created
>> at e.g. session start.
>
> None of them are created at session start. Managed beans are created when
> they
> are first referenced in an expression.
that's correct.
kindest regards,
Reto
|
|
|
Powered by
FUDForum. Page generated in 0.04847 seconds