[
https://issues.apache.org/jira/browse/TAP5-2383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14121227#comment-14121227
]
Chris Poulsen commented on TAP5-2383:
-------------------------------------
[~dmitrygusev]
{quote}
I would say that you don't want components know about each other at all (nor
parent/child or some other way), but it may happen that some component changes
an entity from your domain, and another component is responsible to display the
state of that entity.
{quote}
I'm not saying that it will never happen, I just do not think that it is a
practice that should be encouraged by supporting it out of the box.
{quote}
For example, imagine you have one component that allows editing User's info
(UserInfoEditor) and you have another component that displays user's name &
avatar (UserLink) – and they're all on the same page.
And you want to update all instances of UserLink on the page when you update
the user's info via UserInfoEditor.
How would you do that without pub/sub?
{quote}
It is hard to say without having an actual case.
You could let UserInfoEditor refresh the whole page, you could have
UserInfoEditor trigger an event indicating that user info has changed and have
the appropriate container refresh the necessary zones, you could use a separate
page for user editing automatically giving you the full refresh after edit, you
could implement pub/sub on the server side or client side, whatever you think
is best...
The use case/proposed solution does not seem general enough for it to go into
the framework, IMO.
> 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)