Hi, have a few doubts about using mvp + gin.
One thing that I want to do is this. I want that when my app loads (in the
entry point) load the logged user data and display one or another gui (one
for the root users and other for the normal users).
Obviously in the server I check if the user has the right rol to perform the
action requested via RPC.
This are my doubts:
1. To get the user data, is the best way to do something like this:
public void onModuleLoad() {
ginjector.getUserServiceAsync().getCurrentUser(newAsyncCallback() {
public void onSuccess(UserModel result) {
// store user data somewhere
// display the right gui depending on the user rol
}
public void onFailure(Throwable caught) {
// do some
}
});
2. To store in client code the user data, I was trying to do something like
Thomas said
here
http://stackoverflow.com/questions/5827534/cross-activity-references-using-gwt-with-gin
I've created a CurrentUserProvider class and i've binded my UserModel to my
CurrentUserProvider. And in my Ginjector i've created a method
CurrentUserProvider getCurrentUser();
Then in my rpc callback I put the the user data in the provider.
ginjector.getUserServiceAsync().getCurrentUser(new AsyncCallback()
{
public void onSuccess(UserModel result) {
// store user data somewhere
ginjector.getCurrentUser().setCurrentValue(result);
}
...
It works in some kind, but I don't see it so clean. I believe that it could
be done in a nicer way. Can you please give any idea about how are you
handling this in your projects?
On the other side I have the trouble about displaying one or another gui
depending on the user's rol.
In my Ginjector I have this method AppLayoutView getAppLayout(); that
returns me my applayout. Basically, when the user is root haves one menu,
and when the user is not root, haves another menu. Show I create my menu by
code and do something like this in the view?
if (currentUserProvider.get().getRol().equals(ROLE_ROOT)) {
// create one menu
} else {
// create normal user menu
}
And finally... I have a MvpModule (GinModule) where I have this provider:
@Provides
@Singleton
public PlaceHistoryHandler getHistoryHandler(PlaceController
placeController, PlaceHistoryMapper historyMapper, EventBus eventBus) {
PlaceHistoryHandler historyHandler = newPlaceHistoryHandler(historyMapper);
historyHandler.register(placeController, eventBus, newCompaniesListPlace());
return historyHandler;
}
Where I want to get the user to right place, again, depending on the user's
role. I've tried doing something like this:
@Provides
@Singleton
public PlaceHistoryHandler getHistoryHandler(PlaceController
placeController, PlaceHistoryMapper historyMapper, EventBus eventBus,
CurrentUserProvider currentUserProvider) {
PlaceHistoryHandler historyHandler = new
PlaceHistoryHandler(historyMapper);
if (currentUserProvider.get().getRole().equal(BLA)) {
historyHandler.register(placeController, eventBus, new
CompaniesListPlace());
else {
// go to another place
}
return historyHandler;
}
But what is happening to me is that this method is being called before that
my rpc returns me the user data. So currentUserProvider is not initialized.
How can I handle this?
Any help would preciated!
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/-rnGsn5FArkJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.