In the following code snippet i am using GIN and GUICE with the MVP
Pattern. In my module, i am loading
the class 'AppPresenter':
*** MainApp.java ***
public void onModuleLoad() {
AppPresenter appPresenter = injector.getAppPresenter();
appPresenter.go(RootPanel.get());
injector.getPlaceManager().fireCurrentPlace();
}
Now follow to the method "go", you can see that the "container" is
currently null. The method "checkIsUserInSession()"
decides what to show. I am using Spring Security in the backend to
check user permissions and return a UserModel
with a simple boolean inside it (for this example i have modified it
to make it simple). The methods "showMain()" and
"showLogin()" are adding only components to the container. That's it.
*** AppPresenter.java ***
import com.google.gwt.user.client.ui.HasWidgets;
public class AppPresenter {
private HasWidgets container;
}
public void go(final HasWidgets container) {
this.container = container;
checkIsUserInSession();
}
@SuppressWarnings({"NonBooleanMethodNameMayNotStartWithQuestion"})
private void checkIsUserInSession() {
UserServiceAsync rpcService = GWT.create(UserService.class);
rpcService.getCurrentUser(new FailureCheckingAsyncCallback<UserModel>
() {
@Override
protected void doOnSuccess(UserModel result) {
//noinspection unchecked
if (result.isLoggedIn==true)
showMain();
} else {
showLogin();
}
}
}
);
}
@SuppressWarnings({"MethodOnlyUsedFromInnerClass"})
private void showMain() {
container.clear();
container.add(portalMainWidget.getDisplay().asWidget());
}
private void showLogin() {
container.clear();
container.add(loginComponent.getDisplay().asWidget());
}
Have a lot of fun!
On 4 Nov., 18:39, Yozons Support on Gmail <
yoz...@gmail.com> wrote: