在 GWT 程序中添加历史记录

发布于 2024-11-17 23:10:27 字数 2349 浏览 1 评论 0原文

我正在编写 History.newItem("step2") 但即使在执行此指令之后,它应该调用的方法是 public void onValueChange(ValueChangeEvent event) { //代码 但是

当我这样做时,该方法没有被调用,我不明白为什么它没有调用该方法。

下面是整个代码。

{
package org.adrianwalker.gwt.uploadprogress.client;

import com.google.gwt.user.client.History;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import org.adrianwalker.gwt.uploadprogress.client.view.UploadProgressView;

public final class UploadProgress implements EntryPoint, ValueChangeHandler {

  private static final UploadProgressView UPLOAD_PROGRESS_VIEW = new UploadProgressView();
    Label step_co=new Label("Step1");
  @Override
  public void onModuleLoad() {
    Button next1=new Button("Next");

    AbsolutePanel master_panel=new AbsolutePanel();
    //RootPanel rootPanel = RootPanel.get("content");
      master_panel.setStyleName("master_panel");
      master_panel.setHeight("100px");
      master_panel.setWidth("300px");


    master_panel.add(step_co,100,25);
    RootPanel.get("master").add(master_panel,100,25);
    RootPanel.get("content").add(UPLOAD_PROGRESS_VIEW,100,150);
    RootPanel.get("content").add(next1);

      next1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                History.newItem("step2",true);

               RootPanel.get().add(new Label(History.getToken()));
//                changeStep("token");
          }});

    RootPanel.get("content").add(next1,150,550);

  }



   public void onValueChange(ValueChangeEvent event)
 {
RootPanel.get().add(new Label("In value change"));
 String token=History.getToken();
 changeStep(token);
 }
   public void changeStep(String token)
    {
       if(token.equals("step2"))
       {
           step_co.setText("Step2");
           RootPanel.get("content").clear();
        }
   }


}
}

请告诉我如何调用该方法 public void onValueChange(ValueChangeEvent event) 在 History.newItem(("step2") 指令中。

I am writing History.newItem("step2") but even after executing this instruction the method it should call is public void onValueChange(ValueChangeEvent event)
{
//code
}

but when I am doing so the method is not called I dont understand why it is not calling the method.

Below is the entire code.

{
package org.adrianwalker.gwt.uploadprogress.client;

import com.google.gwt.user.client.History;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import org.adrianwalker.gwt.uploadprogress.client.view.UploadProgressView;

public final class UploadProgress implements EntryPoint, ValueChangeHandler {

  private static final UploadProgressView UPLOAD_PROGRESS_VIEW = new UploadProgressView();
    Label step_co=new Label("Step1");
  @Override
  public void onModuleLoad() {
    Button next1=new Button("Next");

    AbsolutePanel master_panel=new AbsolutePanel();
    //RootPanel rootPanel = RootPanel.get("content");
      master_panel.setStyleName("master_panel");
      master_panel.setHeight("100px");
      master_panel.setWidth("300px");


    master_panel.add(step_co,100,25);
    RootPanel.get("master").add(master_panel,100,25);
    RootPanel.get("content").add(UPLOAD_PROGRESS_VIEW,100,150);
    RootPanel.get("content").add(next1);

      next1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                History.newItem("step2",true);

               RootPanel.get().add(new Label(History.getToken()));
//                changeStep("token");
          }});

    RootPanel.get("content").add(next1,150,550);

  }



   public void onValueChange(ValueChangeEvent event)
 {
RootPanel.get().add(new Label("In value change"));
 String token=History.getToken();
 changeStep(token);
 }
   public void changeStep(String token)
    {
       if(token.equals("step2"))
       {
           step_co.setText("Step2");
           RootPanel.get("content").clear();
        }
   }


}
}

Please tell me how could make this call the method public void onValueChange(ValueChangeEvent event)
in the History.newItem(("step2") instruction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2024-11-24 23:10:27

您必须

History.addValueChangeHandler(this)

在代码中的某个地方调用。这就是历史对象在触发时如何知道调用您的方法的方式。

请查看 GWT 文档,获取一些示例代码。

You will have to call

History.addValueChangeHandler(this)

somewhere in your code. That is how the history object knows to call your method when it's fired.

Check out GWT's documentation for some example code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文