i am trying to add a login/logout feature to my web-app using UserService. Here is the relevant code :
1) the Entry Point class :-
public class MarkerSimple implements EntryPoint {
static LoginInfo loginInfo = null;
@Override
public void onModuleLoad() {
System.out.println("onModuleLoad");
LoginServiceAsync loginService = GWT.create(LoginService.class);
loginService.login(GWT.getHostPageBaseURL(), new AsyncCallback<LoginInfo>() {
public void onFailure(Throwable error) {
System.out.println("ERROR FETChinG Data");
}
public void onSuccess(LoginInfo result) {
System.out.println(result);
loginInfo = result;
if(loginInfo.isLoggedIn()) {
Constants.isLoggenIn = true;
} else {
Constants.isLoggenIn = false;
}
loadLogin();
}
});
}
private void loadLogin() {
RootLayoutPanel.get().add(new GwtMaps());
}
}
2) the Composite class :-
public class GwtMaps extends Composite {
interface LoginWidgetURLBinder extends UiBinder <DockLayoutPanel, GwtMaps> { }
private static LoginWidgetURLBinder uiBinder = GWT.create(LoginWidgetURLBinder.class);
private GoogleMap map;
int i=0;
static Boolean isLoaded = false;
@UiField
Label label1;
@UiField
RadioButton myRadioAble;
@UiField
SimpleLayoutPanel map_canvas;
@UiField
static Anchor signin;
public GwtMaps() {
System.out.println("GwtMaps");
initWidget(uiBinder.createAndBindUi(this));
isLoaded = true;
anchorHandler();
LatLng myLatLng = LatLng.create(28.60753,77.03505);
MapOptions myOptions = MapOptions.create();
myOptions.setZoom(20.0);
myOptions.setCenter(myLatLng);
myOptions.setMapTypeId(MapTypeId.ROADMAP);
map = GoogleMap.create(map_canvas.getElement(), myOptions);
map.addClickListener(new ClickHandler() {
@Override
public void handle(MouseEvent event) {
i++;
addMarker(event.getLatLng());
}
});
}
private void addMarker(LatLng location) {
MarkerOptions newMarkerOpts = MarkerOptions.create();
newMarkerOpts.setPosition(location);
newMarkerOpts.setMap(map);
newMarkerOpts.setTitle("Marker"+i);
newMarkerOpts.setDraggable(true);
newMarkerOpts.setAnimation(Animation.DROP);
Marker.create(newMarkerOpts);
}
public static void anchorHandler() {
if(Constants.isLoggenIn == false) {
signin.setText("SignIn using Google");
signin.setHref(MarkerSimple.loginInfo.getLoginUrl());
} else {
signin.setText("SignOut");
signin.setHref(MarkerSimple.loginInfo.getLogoutUrl());
}
}
}
The problem is if the user was not logged in, even after logging in, following the Anchor, the data received from the RPC is not captured. Also i need a way to change the Anchor dynamically after performing a login or logout so that the same Anchor can perform a logout or login. Please Help
I don't think you can have a static @UiField as your signin is configured.
Do you have the url configured in the .ui.xml because if not I do not see where you are doing a signIn.addClickHandler() and calling the login method.
I would move the login call to your view instead of having it in your module so that you can call it from the anchor with an addClickHandler or a @UiHandler("signin"). And make your module simply load the view.
public class MarkerSimple implements EntryPoint {
@Override
public void onModuleLoad() {
// Just this.
RootLayoutPanel.get().add(new GwtMaps());
}
}