0

当我运行一个包含历史管理的小型登录应用程序时,它在我使用最新的 chrome 和 firefox 版本以及 GWT 2.4 的家中运行良好

当我在办公室运行时,相同的应用程序运行正常。我使用了一个全局静态布尔变量,它在调试模式下具有正确的值,而在我正常运行时它具有错误的值。在使用 IE 7 和 GWT 2.2 的 Office 中

此外,onModuleLoad() 在我的家庭环境中只调用一次,而每次我键入 someURL#sometoken 并按 Enter 键更改内部页面时都会调用它。何时调用 onModuleLoad()。每个会话或每次用户仅加载一次页面(甚至令牌)?

谁能告诉这是由于 IE 7 或 GWT 2.2 或其他问题造成的一些问题。

编辑- 它非常小的应用程序。代码 - -

测试历史.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);
        }           
    }
}

登录.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);
    }
}

存款.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);
    }   
}

提款类与存款相同。我面临的问题是,一旦我登录,我应该能够打开所有在我家完美运行的内部页面(并且 onModuleLoad() 只调用一次),而我每次都必须登录才能在我的办公室(并且 onModuleLoad() 被称为 evrytime)

4

2 回答 2

1

onModuleLoad在页面加载时调用,但是:

  • 在地址栏中按回车键可以在某些浏览器中重新加载页面
  • 从应用程序外部更改URL 中的哈希(在地址栏中键入或使用书签)可能会混淆 IE6/7;当 GWT 检测到它时,它会重新加载页面(查看类内部)。请注意,在历史中导航时不会发生这种情况(这就是隐藏的用途)HistoryImplIE6iframe
于 2011-12-21T17:00:37.083 回答
0

您是否在 html 主机页面的 gwt 中包含了用于历史支持的隐藏 iframe?

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

于 2011-12-21T15:02:42.553 回答