Search code examples
gwtgwtpgwt-platform

GWTP - Clear Presenter Data


What is the recommended way to clear presenter data? I would like to clear my UI on login.

As an example of the current problem, I have a NestedPresenter which is used to collect form data. Someone can log out, then another user can log back in while the browser session is still active, and when the form is revealed the prior user's data is still showing.

Any recommendations?


Solution

  • It highly depends on the navigation you're using in your application. If you're using PlaceManager to navigate in-between almost stateless screens - overriding onReset method is the place I recommend you most, since each time navigation lands a user to the presenter - your clear code will be executed.

    Referring to documentation

    onReset()

    This happens at the end of each user's navigation request. For example if one needs to execute some code when user navigates to a presenter that's already bound, already added to a Slot, this is the method that needs to be overriden. Be careful though, this is called often, so nothing too heavy should be executed in this method.

    Clear your view, then fetch new model. If onReset is too frequent for you - stick with onReveal() then

    onReveal()

    onReveal() will be called when the Presenter is being revealed. In GWTP's vocabulary, this means when a Presenter is added to a Slot Therefore, it doesn't necessarily mean that the object will be visible in the DOM. See this issue to understand the disambiguition. This should be overriden when one wants to update something on the Presenter when it's about to be added to a Slot.

    and if onReveal does not work in your case somehow (you keep the presenters inserted in the slot all the time + navigation requests do not matter) - just clear info each time your presenter is hidden, via overriding onHide()