Question

New to GWT, oh! this learning curve...

So, I'm testing out the authentication functionality I've implemented: When querying for the current user's role through an AsyncCallback, a check is first made to see whether the user is logged in or not. This is done in my own implementation of an AsyncCallback (see How to redirect to login page after session expire in GWT RPC call). If found to be not logged in, the following is happening:

Widget returnToWidget = RootPanel.get(MyApp.Default_RootPanel_Id).getWidget(0);
RootPanel.get().add(new LoginPage(returnToWidget));

and the LoginPage clears the RootPanel, adds a dummy FlowPanel and pops up a DialogBox with username/password/submit widgets. The ClickListener added to the submit widget does the following if credentials are accepted:

@Override
public void onSuccess() {
    RootPanel.get().clear();
    RootPanel.get().add(returnToWidget);

Now, this is working just fine. To address the actual problem, please allow me to get back to the query call, which is taking place in a MainPanel extends Composite:

public MainPanel() {
    final DockPanel dockPanel = new DockPanel();
    initWidget(dockPanel);
    final HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.add(new Button("TEST"));

    authService.getUserRole(jSessionId, new AsyncCallback<Constants.UserRole>() {
        @Override
        public void onSuccess(UserRole currentUserRole) {
            boolean isAdmin = currentUserRole.isAtLeast(Constants.UserRole.Administrator);
            if (isAdmin) {
                hPanel.add(createNewStudyButton);
            }
            hPanel.add(new Button("ButtonForAll"));
            System.out.println("CODE EXECUTED!");
        [...]
        }
    [...]

    dockPanel.add(hPanel, DockPanel.NORTH);
    System.out.println("THROUGH!");
}

What is happening is that when starting my GWT app, MainPanel is instantiated in the EntryPoint and added to RootPanel, resulting in the console printing THROUGH!, the login screen being shown and after providing accepted admin credentials, the passed instance of MainPanel is added to the RootPane.

Unfortunately (and here's the problem!), only the TEST button is shown. The console never prints CODE EXECUTED!. How come the code within the @success response is not being executed? When refreshing the page, the code is executed and all buttons are shown, as the authService.getUserRole now returns a result without an interruption from the login screen.

I'd really, really like a repaint() or something equivalent, but the problem seems to be more of a design issue.

Can anyone please help me getting the code block executed even though the AsyncCallback does a page switch before returning its result?

UPDATE:

My bad! Problem found, but not solved, as I don't think it's solvable within this design:

My SecurityAsyncCallback has a reference to the default AsyncCallback and on onSuccess(T result), it simply passes the the result to the default AsyncCallback, so it reaches the actual caller. My design for handling NotLoggedInException thrown server side on calling e.g. authService.getUserRole is to catch it in my SecurityAsyncCallback's onFailure and show the login screen... but from here I cannot re-run the code that resulted in the onFailure, so that the caller will experience an onSuccess, as the user is now logged in; the AsyncCallback interface is just an intermediary for passing results of the call between caller and callee and has no knowledge of what has been called.

Well, what I'm really after is that when user has digged himself deep into my app, leaves his computer and his login times out, I want the login page to be shown on next server side access and then redirect him back to where he came from (that is, not back to the default page after logging in). I guess I can achieve this through the use of the History subsystem, but I haven't yet tried this.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top