Author |
Message |
25/04/2008 15:35:37
|
schmuck
Power User
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
|
|
|
25/04/2008 15:41:22
|
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
|
|
|
25/04/2008 15:42:50
|
CaptainCasa
Power User
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 |
|
|
25/04/2008 15:44:28
|
CaptainCasa
Power User
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 |
|
|
25/04/2008 15:48:13
|
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
|
|
|
25/04/2008 15:51:21
|
CaptainCasa
Power User
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 |
|
|
25/04/2008 15:58:27
|
hilka
Power User
Joined: 23/11/2007 09:00:08
Messages: 191
Offline
|
Or yours is to slow ...
|
|
|
30/04/2008 14:16:15
|
schmuck
Power User
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.
|
|
|
|