Very cute. It's something akin to GWT's event buses, but server-side.
A less cute alternative, but one which and has served my needs to date and is
straight-forward, is to have the container call a method on each interested
component. You can see it in the following example. Page Persons has several
event handlers that call list.doChangeOfSelectedPerson().
http://jumpstart.doublenegative.com.au/jumpstart7/together/ajaxcomponentscrud/persons
Some extra benefits are that it doesn't need @Persist, and each piece has the
opportunity to set up or pass parameters.
Cheers,
Geoff
On 20 Jun 2014, at 2:50 pm, Paul Stanton <[email protected]> wrote:
> This seems to work, but i'm not sure i trust it!
>
> anyone have a better idea? It would be great to be able to subscribe to an
> event thrown by the container...
>
> MyPage {
> @Persist
> Private List<Runnable> listeners;
>
> void setupRender() {
> listeners = new ArrayList<>();
> }
>
> public void addListener(Runnable r) {
> listeners.add(r);
> }
>
> void onSomeEvent() {
> doSomeProcessing();
> for (Runnable l : listeners)
> l.run();
> }
> }
>
> MyEmbeddedComponent {
> @Inject
> private ComponentResources resources;
>
> void setupRender() {
> ((MyPage) resources.getPage()).addListener(new Runnable() {
> public void run() {
> listenerMethod();
> }
> });
> }
>
> void listenerMethod() {
> doSomething();
> }
> }
>
> On 23/03/2013 3:36 AM, Howard Lewis Ship wrote:
>> ive tought this woud be a cool feature, but it does not exist yet.
>>
>> On Thursday, March 21, 2013, Paul Stanton wrote:
>>
>>> Hi all,
>>>
>>> Is there a way to trigger an event in a container (Page) which notifies
>>> embedded components?
>>>
>>> I'm hoping to do something like this (pseudo code) :
>>>
>>> Page
>>> {
>>> void onSomeEvent()
>>> {
>>> notifyListeners("**SomethingHappened");
>>> }
>>> }
>>>
>>> EmbeddedComponent
>>> {
>>> void setupRender()
>>> {
>>> page.listenTo("**SomethingHappened");
>>> }
>>>
>>> void onSomethingHappened()
>>> {
>>> // called when triggered by page
>>> }
>>> }
>>>
>>> Help appreciated, thanks, paul.
>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>