在 GWT 程序中添加历史记录
我正在编写 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须
在代码中的某个地方调用。这就是历史对象在触发时如何知道调用您的方法的方式。
请查看 GWT 文档,获取一些示例代码。
You will have to call
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.