[
https://issues.apache.org/jira/browse/TAP5-2383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14121385#comment-14121385
]
Dmitry Gusev commented on TAP5-2383:
------------------------------------
Meanwhile I've implemented the support for @Subscribe annotation in
anjlab-tapestry-commons 1.6.0 for page/component classes and for event handlers
too.
So an example from original proposal will (almost) work as is. "Almost" because
when specified on event handlers it must not have eventType in its declaration,
so you should specify event name using the "@OnEvent" annotation or it will be
computed from the method name (the same as it works for normal events).
So both examples below are equivalent:
{code:java}
@Subscribe
@OnEvent("Event1")
public boolean onEvent1(EventContext context)
{
// handle event
}
{code}
and
{code:java}
@Subscribe
public boolean onEvent1(EventContext context)
{
// handle event
}
{code}
@Subscribe could also be put on the class level:
{code:java}
@Subscribe({ "Event1" })
public class Component1
{
// ...
}
{code}
If put on classes at least one eventType should be present in the declaration.
It's not necessary to declare event handlers in the same component, because
they will be bubbled. Though at least one handler should be present in parent
component, otherwise runtime exception will be thrown.
> Serverside publish / subscribe mechanism
> ----------------------------------------
>
> Key: TAP5-2383
> URL: https://issues.apache.org/jira/browse/TAP5-2383
> Project: Tapestry 5
> Issue Type: New Feature
> Components: tapestry-core
> Reporter: Lance
> Priority: Minor
>
> In some cases, an event in one component should cause an action (eg ajax
> update) in another. When these components are siblings it sometimes gets
> tricky having to pass zone id's around and having one component update the
> other.
> It would be nice to decouple the components with a serverside pub/sub
> mechanism. Here's an initial brain dump on how it could work.
> {code:java}
> public class EditPersonComponent {
> @Parameter
> private Person person;
> @Inject
> private PersonDao personDao;
> @Inject
> private ComponentResources componentResources;
> // lets assume there's a form in the component which gets posted
> void onSuccessFromPersonForm() {
> personDao.save(person);
> componentResources.publish("personUpdated", person); // new method on
> ComponentResources
> }
> }
> {code}
> {code:java}
> public class SomeOtherComponent {
> @Inject
> private AjaxResponseRenderer ajaxResponseRenderer;
> @Property
> private Person person;
> @Inject
> private Zone personZone;
> // new subscribe annotation (and naming convention?)
> @Subscribe("personUpdated")
> void onPersonUpdatedPublished(Person person) {
> this.person = person;
> ajaxResponseRenderer.addRender(personZone);
> }
> }
> {code}
> If this change was made on ComponentResources, we should probably add the
> following to support invoking publish events on the client
> {code}
> Link ComponentResources.createPublishLink(String eventType, Object... context)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)