Sunday, April 13, 2014

How to fix the delemma in control the gui when user logins in GWTP?

Ok, here is my dilemma:

I got a Header presenter which is the nested presenter. The Customer presenter is the child of Header presenter (ie the Customer presenter was put into a slot of Header presenter).

There is Login Panel in Header presenter.

-So here is the requirements:

-Users can not see any Gui of Customer presenter if they have not logged in yet.

-When the user logins successfully then it will visible the Gui of Customer presenter.

-When User refreshes the page, the system will check if the customer logined. If he/she did login, then the system will show Gui of Customer presenter. If he/she has not logined, then prompt an error message.

So here is what I did.

In Header presenter, I have a method loginedSuccessfully(), this method will passUserInfo() (use eventBus) into Customer presenter.

In Customer presenter, I have:

private int custID=0;  public void onReset(){     super.onReset();     if(custID>0){         showGui();     }     else{         hideGui(); // he hideGui() has Window.alert("Pls Login");     }  }  private PassUserInfoHandler passUserInfoHandler=new PassUserInfoHandler(){        @Override      public void onPassUserInfo(PassUserInfoEvent event) {         custID=event.getCustID();         if(custID>0){             showGui();         }         else{            hideGui();         }      }    };  

When user refresh the Customer page. The onResetwill be called, if customer has not logined yet then it won't show Gui & prompt a message.

When user logins by clicking login button then passUserInfoHandler will be called & it will show the Gui if logged in ok.

But here is the problem. When user already logged in & if I open a new browser Tab & re-open the Customer page, then this time both onReset & passUserInfoHandler waere called & the page prompts the message TWICE. This is not Good.

But why that happened?

This is because the onReset was called before the passUserInfoHandler was called. That is why checking gui method was called 2 times.

I used Scheduler.get().scheduleDeferred(new Command() {}; but it didn't work.

Do you know how to fix the problem so that it can meet all the above requirements?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment