我正在尝试使用 UserService 向我的网络应用程序添加登录/注销功能。以下是相关代码:
1)入口点类:-
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)复合类: -
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());
}
}
}
问题是如果用户没有登录,即使在登录之后,跟随 Anchor,从 RPC 接收到的数据也不会被捕获。我还需要一种在执行登录或注销后动态更改 Anchor 的方法,以便同一个 Anchor 可以执行注销或登录。请帮忙