How to reveal a presenter on consumption of a event with a @ProxyEvent (case of Product -> Product Details)
1. I have successfully created my event:
public class ShowDetailsEvent extends GwtEvent<ShowDetailsEvent.ShowDetailsHandler> {
public interface ShowDetailsHandler extends EventHandler {
void onShowDetailsEvent(ShowDetailsEvent event);
}
public static final Type<ShowDetailsHandler> TYPE = new Type<>();
public static Type<ShowDetailsHandler> getType() {
return TYPE;
}
@Override
public Type<ShowDetailsHandler> getAssociatedType() {
return TYPE;
}
private Product product;
public Product getProduct() {
return product;
}
public ShowDetailsEvent(Product product) {
this.product = product;
}
public static void fire(HasHandlers source, Product product) {
source.fireEvent(new ShowDetailsEvent(product));
}
@Override
protected void dispatch(ShowDetailsHandler handler) {
handler.onShowDetailsEvent(this);
}
}
2. I have collected the UI triggering event from a ProductView:
@UiHandler("name")
public void onClick(ClickEvent event) {
getUiHandlers().showProductDetails();
}
3. Then, I have fired it from my ProductPresenter
Product product;
@Override
public void showProductDetails() {
ShowDetailsEvent.fire(this, product);
}
4. I managed to send it to a registered DetailsPresenter showing details of the product
@ProxyEvent
@Override
public void onShowDetailsEvent(ShowDetailsEvent event) {
dispatcher.execute(new GetDetailsRequest(event.getProduct()), new AsyncCallback<GetDetailsResult>() {
@Override
public void onFailure(Throwable caught) {
// process failure
}
@Override
public void onSuccess(GetDetailsResult result) {
getView().setProduct(result.getDetails());
}
});
}
5. And finally, I was able to render the product when showing the screen.
@Override
public void setProduct(Product product) {
// replace product data in UiBinder
}
However, some questions come now to my mind:
* How to reveal the DetailsPresenter when the event is consumed. Should I use a manual reveal with prepareFromRequest
? How?
* when I manually reveal the presenter, is the history updated?
* How to show an URL bookmarkeable for this particular product details page?
Thanks