I've designed our application without open event, by using javax.enterprise.event.Event in this way I'm decoupling the dialog bean with the "source view".
Every button which calls popup.show() also invoke actionListener with unique eventId, then in your "view" you must implement the @Observes logic.
Eg:
Code: Select all
...
public class CustomerSelector{
...
@Inject
@CustomerSelectionEvent
private Event<Customer> selectEvent;
public void initialize(String eventId) {
this.eventId = eventId;
}
public void select() {
selectEvent.select(new EventIdQualifier(eventId)).fire(getSelected());
}
...
}
Code: Select all
public class SomeViewBean{
...
private void method1(@Observes(notifyObserver = Reception.IF_EXISTS) @EventId("method1.event") @CustomerSelectionEvent customer) {
this.customer1=customer;
}
private void method2(@Observes(notifyObserver = Reception.IF_EXISTS) @EventId("method2.event") @CustomerSelectionEvent customer) {
this.customer2=customer;
}
...
}
in your xhtml you would have:
Code: Select all
<p:commandButton value="method1" actionListener="#{customerSelector.initialize('method1.event')}" oncomplete="myDialog.show();">
<p:commandButton value="method2" actionListener="#{customerSelector.initialize('method2.event')}" oncomplete="myDialog.show();">
In this way your button will be connected to the method1/method2 by using unique eventID and not to the dialog, so you will be able to reuse it from many views.
Regards,
Dima