Can we just let "prepareFromRequest" to behave just like traditional non-Ajax page?

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

  •  18-06-2023
  •  | 
  •  

Question

Ok, let see how traditional non-Ajax page work. Suppose you have a page like the below link

abc.com#!search;item=car

In the traditional non-Ajax website, when first time you call "abc.com#!search;item=car", it will go to server and get data. After that you go to other page like "abc.com#!customer;name=tom" and then you hit back button it will go back to "abc.com#!search;item=car". However, this time it won't call to the server again cos it remembered it did before.

Now Here is the GWTP problem. Suppose the above abc.com was built in GWTP technology.

At the first time wen user enters the "abc.com#!search;item=car", the GWTP app will initialize the page "search" via onBind, then the prepareFromRequest will be called & it will go to server to get data.

That is Good, no problem. However, if we open a new page (like customer page) by using revealPlace, then we hit the back button it will go back to "search" page & it will call prepareFromRequest again. The prepareFromRequest will then make the exactly same call to server again. That is not good cos it wastes resource.

So I want the "prepareFromRequest" to be called ONLY at the time we initialise the page (run after onBind) & block the "prepareFromRequest" in all other page request (ex like user press the back button).

It mean "prepareFromRequest" should work just like traditional non-Ajax page mentioned above.

Can we do that? or

Do you have a better solution?

Was it helpful?

Solution

Why don't you just check in your prepareFromRequest method if you have already a search result for that specific searchterm and only issue a call to the backend if it has changed?

Something like this:

public Presenter extends .... {

    String searchItem = null;
    List<DTO> searchResult = null;

    @Override
    public void prepareFromRequest(PlaceRequest placeRequest) {
        super.prepareFromRequest(placeRequest);
        String item = placeRequest.getParameter("item",null));
        if (searchItem == null || !searchItem.equals(item)) {
            searchItem = item;
            // MAKE A CALL TO THE BACKEND AND STORE THE DATA IN A FIELD. 
            searchResult = GET_FROM_SERVER(searchItem);
       }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top