运行小历史GWT应用程序时的困惑
当我运行一个包含历史记录管理的小型登录应用程序时,它在我的家中运行良好,我使用的是最新的chrome和firefox版本以及GWT2.4 当我在办公室运行时,同样的应用程序工作异常。我使用了一个全局静态布尔变量,它在调试模式下具有正确的值,而在正常运行时具有错误的值。办公室即时通讯使用IE7和GWT2.2 此外,onModuleLoad()在我的主环境中只调用一次,而每次键入someURL#sometoken并按enter键更改内部页面时都会调用它。何时调用onModuleLoad()。每个会话或evrytime用户只加载一次页面(甚至令牌) 有人能告诉我这是由于IE7或GWT2.2或其他问题造成的吗 编辑——这是一款非常小的应用程序。代码--- TestHistory.java Deposit.java运行小历史GWT应用程序时的困惑,gwt,cross-browser,version,gwt-history,Gwt,Cross Browser,Version,Gwt History,当我运行一个包含历史记录管理的小型登录应用程序时,它在我的家中运行良好,我使用的是最新的chrome和firefox版本以及GWT2.4 当我在办公室运行时,同样的应用程序工作异常。我使用了一个全局静态布尔变量,它在调试模式下具有正确的值,而在正常运行时具有错误的值。办公室即时通讯使用IE7和GWT2.2 此外,onModuleLoad()在我的主环境中只调用一次,而每次键入someURL#sometoken并按enter键更改内部页面时都会调用它。何时调用onModuleLoad()。每个会话
类别取款与存款相同。
我所面临的问题是,一旦我登录,我就应该能够打开所有在家中正常工作的内部页面(onModuleLoad()只调用一次),而我必须每次登录才能在办公室打开内部页面(onModuleLoad()称为evrytime)您是否在html主机页中包含了gwt中隐藏的iframe for history支持
请参见
onModuleLoad在加载页面时调用
,但是:
- 在地址栏中按enter键可以在某些浏览器中重新加载页面
- 从应用程序外部更改URL中的哈希(键入地址栏或使用书签)可能会混淆IE6/7;当GWT检测到它时,它会重新加载页面(查看
类)。请注意,在历史记录中导航时不会发生这种情况(这就是隐藏的HistoryImplIE6
的作用)iframe
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);
}
}
}
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);
}
}
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);
}
}