In GWTP, what are the difference of onBind, prepareFromRequest, revealInParent, onReveal, onReset in Context of Present-ChildPresenter? Very Confused

StackOverflow https://stackoverflow.com/questions/21213690

  •  29-09-2022
  •  | 
  •  

Question

I am using GWTP, I am also using NestedPresenter in a form of parentPresenter (Ex: HeaderPage) and childPresenter (ContentPage). I also want to send info from parentPresenter to childPresenter (Ex: when user Loginned in HeaderPresenter then the info will be pass onto the childPresenter).

Now, I am very confusing about the difference among onBind, prepareFromRequest, revealInParent, onReveal, onReset.

Google said (https://code.google.com/p/gwt-platform/wiki/FrequentlyAskedQuestions#How_do_I_choose_between_onReveal()_and_onReset()?) "On First Load, onBind will be called first then prepareFromRequest will be called sencond, revealInParent called 3rd, then onReveal, then onReset".

So here are the list of my questions:

-When a page that have Header & Content, then cycle (onBind, prepareFromRequest, revealInParent, onReveal, onReset) will be called first in parent header presenter, then after that all same cycle (onBind, prepareFromRequest, revealInParent, onReveal, onReset) will be called second in child or nested content presenter?

Or both parentPresenter & childPresenter go through the cycle independently?

If they go through the cycle independently, then we can have a problem. Ex, whenever user refreshes the page (header+content), if the header already checked the session, then I want the header pass the session info into the child content page, but since they go through the cycle independently then how parent presenter pass info when child presenter has not initialized?

Second question is how to know which method should to be put put into which cycle?

Was it helpful?

Solution

Your web application can be seen as a tree of Presenters. Walking the tree from bottom to top, onBind will be called on each Presenter. Once all Presenters are bound, onReveal will be called on each Presenter, from the top to the bottom of the tree. The prepareFromRequest method will be called before onReveal.

So, onBind will be called first on ChildPresenter, then onBind will be called on ParentPresenter, then onReveal will be called on ParentPresenter, and finally onReveal will be called on ChildPresenter.

There's no risk that ChildPresenter will not be initialized when ParentPresenter checks the session.

To communicate from the ParentPresenter to the ChildPresenter, I suggest 2 approaches:

  • When the session is fetched by ParentPresenter, ParentPresenter fires a SessionLoadedEvent through the EventBus, and ChildPresenter registers to that event and reacts to it

  • When the session is fetched by ParentPresenter, ParentPresenter calls childPresenter.onSessionFetched(sessionData) directly. ChildPresenter will do whatever he wants with sessionData inside the onSessionFetched method.

You can also see this https://github.com/ArcBees/GWTP/wiki/Presenter-Lifecycle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top