Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JavaServer Faces » Loop through the Mbeans in Session Scope
Loop through the Mbeans in Session Scope [message #475547] Tue, 04 March 2008 14:12 Go to next message
Eclipse UserFriend
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 #475548 is a reply to message #475547] Tue, 04 March 2008 14:55 Go to previous messageGo to next message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 #475549 is a reply to message #475548] Tue, 04 March 2008 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: reto.huber.alabus.com

>"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
Re: Loop through the Mbeans in Session Scope [message #475591 is a reply to message #475549] Tue, 04 March 2008 15:45 Go to previous messageGo to next message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 #475595 is a reply to message #475547] Wed, 05 March 2008 09:59 Go to previous messageGo to next message
Wolfgang Knauf is currently offline Wolfgang KnaufFriend
Messages: 63
Registered: July 2009
Member
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 #475596 is a reply to message #475595] Wed, 05 March 2008 13:22 Go to previous messageGo to next message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 #475607 is a reply to message #475596] Thu, 13 March 2008 17:09 Go to previous message
Eclipse UserFriend
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 14:55 Go to previous message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 #617147 is a reply to message #475548] Tue, 04 March 2008 15:22 Go to previous message
Eclipse UserFriend
Originally posted by: reto.huber.alabus.com

>"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
Re: Loop through the Mbeans in Session Scope [message #617455 is a reply to message #475549] Tue, 04 March 2008 15:45 Go to previous message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 09:59 Go to previous message
Wolfgang Knauf is currently offline Wolfgang KnaufFriend
Messages: 63
Registered: July 2009
Member
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 13:22 Go to previous message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
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 17:09 Go to previous message
Eclipse UserFriend
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
Previous Topic:Trinidad support? Anywhere?
Next Topic:Asking jsf semantics validator for ISymbol created from jsf tag attribute
Goto Forum:
  


Current Time: Tue Dec 23 00:23:26 GMT 2014

Powered by FUDForum. Page generated in 0.02032 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software