How to Retrive the Logedin User in MasterHead widgets

78 views
Skip to first unread message

Pradeep Seth

unread,
May 8, 2012, 4:52:18 PM5/8/12
to gwt-cx
Hi Group

I am referring this application for last two week for my project.
I have following Question please help me
Question #1
How to Retrive or fetch the Logedin/Current User in MasterHead
widgets also other view pages also, To display on Master Head (EX:
Welcome XYZ)

I am using
gwt2.2,gwtp 0.6? windows 7

Thanks
Pradeep

Rob

unread,
May 8, 2012, 7:58:36 PM5/8/12
to gwt-cx
Hi,

I have been focused on adding support for Ext GWT 3.0 and GAE (and JPA
support via DataNucleus) to gwt-cx.

However, what you need to do is quite straight forward. Browse the
source code for the Serendipity Smart GWT sample and taker a look at
the sendCredentialsToServer method in the SignInPage Presenter:

->
...

@Override
public void onSuccess(LoginResult result) {
CurrentUser currentUser = new
CurrentUser(getView().getUserNameText());

LoginAuthenticatedEvent.fire(getEventBus(), currentUser);

PlaceRequest placeRequest = new
PlaceRequest(NameTokens.mainPage);
if (! redirectToken.isEmpty()) {
placeRequest = placeRequest.with(REDIRECT, redirectToken);
}
getPlaceManager().revealPlace(placeRequest);

Log.debug("onSuccess() - Session Key: " +
result.getSessionKey());
}

->

If the LoginAction returns successfully then a LoginAuthenticatedEvent
is fired.

The Masthead just needs to subscribe to the event (like the
LoggedInGateKeeper class) and then it will be able to update the
current user (name):

->

...

@Inject
public LoggedInGatekeeper(final EventBus eventBus) {

this.eventBus = eventBus;

this.eventBus.addHandler(LoginAuthenticatedEvent.getType(), new
LoginAuthenticatedEventHandler() {
@Override
public void onLoginAuthenticated(LoginAuthenticatedEvent event)
{

currentUser = event.getCurrentUser();

Log.debug(currentUser.getLogin() + " credentials have been
authenticated.");
}
});
}

->

A similar approach is also used in the Ext GWT sample.

Note: Check the gwt-cx parent POM for the correct version numbers
(e.g. GWT 2.4, Smart GWT 2.4, Ext GWT 3.0, ...)

Cheers
Rob

http://code.google.com/p/gwt-cx/

Pradeep Seth

unread,
May 9, 2012, 2:49:24 PM5/9/12
to gwt-cx
Hi Rob, Thanks for reply,
I have tried as following way on Masthead.java.
But addHandler method part is not executing.

and on ClientModule.java have added
bind(Masthead.class).in(Singleton.class);

Please help me.

@Inject
public Masthead(final EventBus eventBus)
{
super();
this.eventBus = eventBus;
this.eventBus.addHandler(LoginAuthenticatedEvent.getType(), new
LoginAuthenticatedEventHandler()
{
@Override
public void onLogin(LoginAuthenticatedEvent event)
{
currentUser = event.getCurrentUser();
System.out.println(currentUser.getLogin() + " credentials have
been authenticated."+currentUser.getUserType());

//Log.debug(currentUser.getLogin() + " credentials have been
authenticated.");
}
});

GWT.log("init Masthead()...", null);
------------
2nd Issue
-------------
when i use @UseGatekeeper I am getting this error
00:15:30.335 [ERROR] [nricanapp] The Ginjector
'<mypkg>.client.gin.ClientGinjector' does not have a get() method
returning ''<mypkg>.client.presenter.LoggedInGatekeeper'. This is
required when using @UseGatekeeper.

@ProxyCodeSplit
@NameToken(NameTokens.mainSmartGwtPage)
@UseGatekeeper(LoggedInGatekeeper.class)
public interface MyProxy extends Proxy<MainPageSmartGwtPresenter>,
Place
{
}

Please help me.
Thanks
Manoj

Rob

unread,
May 9, 2012, 10:36:45 PM5/9/12
to gwt-cx
Hi,

1. There is another example of using custom events in the Ext GWT
sample. Take a look at the main page presenter:

-> MainPagePresenter:

...

@Inject
public MainPagePresenter(final EventBus eventBus, MyView view,
MyProxy proxy,
PlaceManager placeManager) {
super(eventBus, view, proxy, placeManager);

getView().setUiHandlers(this);

MainPagePresenter.navigationPaneHeader =
getView().getNavigationPaneHeader();

getEventBus().addHandler(NavigationPaneUpdateEvent.getType(), new
NavigationPaneUpdateEventHandler() {
@Override
public void onUpdateNavigationPane(NavigationPaneUpdateEvent
event) {

Log.debug("onUpdateNavigationPane(NavigationPaneUpdateEvent
event)");


getNavigationPaneHeader().setHeadingText(event.getDisplayName());
}
});
}

->

2. In order to support multiple form factors (desktop, tablet, mobile)
the Serendipity sample uses the "Ginjector provider" approach - so
that you can bind different Gin Modules to different Ginjector's.
Take a look the module definition file (gwt.xml) and the files in the
"com.gwtcx.sample.serendipity.client.gin" package.

-> DesktopGinjectorProvider:

public class DesktopGinjectorProvider implements GinjectorProvider {

@Override
public SerendipityGinjector get() {

Log.debug("DesktopGinjectorProvider - get()");

return GWT.create(DesktopGinjector.class);
}
}

->

-> DesktopGinjector:

@GinModules({DispatchAsyncModule.class, SharedGinModule.class,
DesktopGinModule.class})
public interface DesktopGinjector extends SerendipityGinjector {

}

->

-> DesktopGinModule:

public class DesktopGinModule extends AbstractPresenterModule {

@Override
protected void configure() {

//
// Presenters
//

bindPresenter(MainPagePresenter.class,
MainPagePresenter.MyView.class,
MainPageDesktopView.class, MainPagePresenter.MyProxy.class);

bindPresenter(DashboardsPresenter.class,
DashboardsPresenter.MyView.class,
DashboardsDesktopView.class,
DashboardsPresenter.MyProxy.class);
}
}

->

Note: Check the gwt-cx parent POM for the correct version numbers
(e.g. GWT 2.4, Smart GWT 2.4, Ext GWT 3.0, ...)

Cheers
Rob

http://code.google.com/p/gwt-cx/

Reply all
Reply to author
Forward
0 new messages