Frage

When I am running a small login application consisting of history management, it works fine at my home where im using latest chrome and firefox versions and GWT 2.4

The same application when I run at my office works wild. I have used a Global static boolean variable which has correct value in the debug mode while it has wrong value when I run it normally. In Office Im using IE 7 and GWT 2.2

Also, onModuleLoad() is called only once at my home environment whereas it is called everytime when I type someURL#sometoken and press enter to change the internal page. When is onModuleLoad() called. Only once per session or evrytime user loads some page (or even token)?

Can anyone tell is this some problem due to IE 7 or GWT 2.2 or some other issue.

EDIT - Its very small app. Code ---

TestHistory.java

public class TestHistory implements EntryPoint, ValueChangeHandler<String> {

    static boolean isLoggedIn = false;
    static final String PAGENAME = "mainscreen";
    public void onModuleLoad()
    {
        History.addValueChangeHandler(this);

        String startToken = History.getToken();
        System.out.println("onModuleLoad Called..... start token= -------"+startToken+"--------");
        if(startToken.isEmpty())
            History.newItem("login");
        else
            History.fireCurrentHistoryState(); //to execute onValueChange 1st time since 1st time history is not setup
    }

    @Override
    public void onValueChange(ValueChangeEvent<String> event) {

        String token = event.getValue();
        System.out.println("onValueChange called with token = ***"+token+"***");

        String args = "";
        int question = token.indexOf("?");
        if (question != -1) {
        args = token.substring(question + 1);
        token = token.substring(0, question);
        }

        if(!isLoggedIn)
        {
            if(token.isEmpty() || "login".equals(token))    //1st time opened the site normally
                new Login().display(false, RootPanel.get());
            else {
                new Login().display(true, RootPanel.get());
            }
        }
        else    //User has logged in
        {
            if(token.isEmpty() || "login".equals(token))
            {
                if(isLoggedIn)
                    Window.alert("Ur already logged in!!!");
                else
                    new Login().display(false, RootPanel.get());
            }
            else if("withdraw".equals(token))
                new Withdraw().display(RootPanel.get(), args);
            else if("deposit".equals(token))
                new Deposit().display(RootPanel.get(), args);
            else //token not clear
                Window.alert("Unrecognized token=" + token);
        }           
    }
}

Login.java

public class Login {
    static final String PAGENAME = "login";
    void display(final boolean hasTypedSomeToken,final Panel myPanel) //Process login
    {
        System.out.println("login display called");
        Label displayLabel = new Label("This is the Login Page");
        Label enterName = new Label("Enter ur name");
        final TextBox txtName = new TextBox();
        Label enterPasswd = new Label("Enter ur Passwd");
        final TextBox txtPasswd = new TextBox();
        Button btnLogIn = new Button("Login", new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {

                /* Real app will check DB. Here we r jst chckng d txt fields hv value */
                if(txtName.getValue().length()>0 && txtPasswd.getValue().length()>0)
                {
                    TestHistory.isLoggedIn = true;
                    if(hasTypedSomeToken) {
                        System.out.println("adsljasdlfjljkfsd");
                        History.fireCurrentHistoryState();
                        System.out.println("hoolala  "+History.getToken());
                    }
                    else
                    {
                        myPanel.clear();
                        Label displayLabel = new Label("Thank U for logging. U can now access the application.");
                        myPanel.add(displayLabel);
                    }
                }   
            }
        });         
        myPanel.clear();
        myPanel.add(displayLabel);
        myPanel.add(enterName);
        myPanel.add(txtName);
        myPanel.add(enterPasswd);
        myPanel.add(txtPasswd);
        myPanel.add(btnLogIn);
    }
}

Deposit.java

public class Deposit {
    static final String PAGENAME = "deposit";
    void display(Panel myPanel, String param)
    {
        System.out.println("deposit display called");
        myPanel.clear();
        Label displayLabel = new Label("This is the Deposit Page & ur parameter = "+param+")");
        myPanel.add(displayLabel);
    }   
}

Class Withdraw is same as Deposit. The problem Im facing is that once Im logged in I should be able to open all the internal pages which works perfectly at my home (and onModuleLoad() is called just once) whereas I have to log in everytime to open a internal page at my office (and onModuleLoad() is called evrytime)

War es hilfreich?

Lösung

onModuleLoad is called when the page is loaded, but:

  • pressing the enter key while in the address bar can reload the page in some browsers
  • changing the hash in the URL from outside the application (typing in the address bar, or using a bookmark) can confuse IE6/7; when GWT detects it, it reloads the page (have a look inside the HistoryImplIE6 class). Note that it does not happen when navigating in the history (this is what the hidden iframe is for)

Andere Tipps

Did you included the hidden iframe for history support in gwt in your html host page?

See http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideCodingBasicsHistory.html#mechanism

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top