[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
How to access one ManagedBean form another ManagedBean  XML
Forum Index -> Development
Author Message
schmuck

Power User
[Avatar]

Joined: 08/04/2008 16:27:16
Messages: 83
Offline

Hello,

do you have an example how to access one Bean from another one?

I think must call getDispatchedBean(Class dispatchedBeanClass), but how do I access the main dispatcher?

As a bean, i don't know who is "my" owning dispatcher.


thanks,
Michael Schmuck
[ICQ]
hilka

Power User

Joined: 23/11/2007 09:00:08
Messages: 191
Offline

Hello,

do you have to know your owning bean? We thought we have the same problem, but in the end, we mostly just needed some session information (like the login language).
In the case where there is a details bean within another bean, we implement a little interface that reacts on actions in the details bean (like refresh the overview list after saving the details information).

Tobias
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

Hi,

assuming that you use a sub-class of "DefaultDisptachter" (e.g. WorkpageDispatchter):

When extending your classes from "DefaultDispatchredBean" then the dispatcher is passed through the constructor and later on accessible via "getOwningDispatcher()".

This is the code of DefaultDispatchedBean, so you see: there is no magic behin. The Dispatcher - when creating a bean instance for a certain class - first checks if this class subclasses "DefaultDispatchedBean" (and then uses the specific constructor). Otherwise it uses the normal constructor without parameters.

Code:
 package org.eclnt.jsfserver.managedbean;
 
 /**
  * Default implementation of bean that is managed by a dispatcher. The bean
  * gets passed the dispatcher that is owning the bean via its constructor.
  */
 public class DefaultDispatchedBean
 {
     // ------------------------------------------------------------------------
     // inner classes
     // ------------------------------------------------------------------------
     
     // ------------------------------------------------------------------------
     // members
     // ------------------------------------------------------------------------
     
     private IDispatcher m_dispatcher;
     
     // ------------------------------------------------------------------------
     // constructors
     // ------------------------------------------------------------------------
     
     public DefaultDispatchedBean(IDispatcher dispatcher)
     {
         m_dispatcher = dispatcher;
     }
     
     // ------------------------------------------------------------------------
     // public usage
     // ------------------------------------------------------------------------
     
     public IDispatcher getOwningDispatcher()
     {
         return m_dispatcher;
     }
     
     // ------------------------------------------------------------------------
     // private usage
     // ------------------------------------------------------------------------
     
 }
 


Björn

Björn Müller, CaptainCasa GmbH
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

...forgot to mention: once having the dispatcher, you can ask this one (as you already mentioned) "getDispatchedBean()"...

Björn

Björn Müller, CaptainCasa GmbH
hilka

Power User

Joined: 23/11/2007 09:00:08
Messages: 191
Offline

Ok, got your question wrong. We built the workplace/dispatcher management on our own, so that is what my answer was refering to. Wish we were lucky too and had a dispatcher/workplace solution from the beginning...

Tobias
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

...your development speed is too fast. So, it's your fault.
Björn...

Björn Müller, CaptainCasa GmbH
hilka

Power User

Joined: 23/11/2007 09:00:08
Messages: 191
Offline

Or yours is to slow ...
schmuck

Power User
[Avatar]

Joined: 08/04/2008 16:27:16
Messages: 83
Offline

Thank you all for your help.

Extending my class with DefaultDispatchedBean solved my problem as described above.
[ICQ]
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team