我有一个包含大量视图的应用程序。我遵循的顺序是,当应用程序启动时,它显示“登录”视图。当我登录时,显示“SelectPerson”视图,显示许多人的可选图像。当我选择图像时,会显示“AwardOverview”视图。然后我选择按钮返回显示的“SelectPerson”视图。但是,也会出现“正在加载奖励概述,请稍候......”(在“AwardOverview”视图中弹出一个)消息。这表明尽管行“rootPanel.remove(AwardOverview);”,“AwardOverview”视图也在后台重新加载。代码如下。
如何正确删除“AwardOverview”视图(一旦我获得此信息,我将为所有视图实现它。)
此致
格林
package org.AwardTracker.client;
/**
* The purpose of this package is to define the
* entry point classes onModuleLoad(). List each
* view below.
* If you add a view here then also update NavHandler.java.
*/
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class AwardTracker implements EntryPoint {
public void onModuleLoad() {
NavHandler nav = new NavHandler(RootPanel.get());
nav.setLogin(new LoginView(nav));
nav.setNewAccount(new CreateAccountView(nav));
nav.setUpdateAccount(new UpdateAccountView(nav));
nav.setSelectPerson(new SelectPersonView(nav));
nav.setAwardOverview(new AwardOverviewView(nav));
nav.setAwardGroup(new AwardGroupView(nav));
nav.setEditYouthMember(new EditYouthMemberView(nav));
nav.setEditAwards1(new EditAwardsView1(nav));
nav.setEditAwards2(new EditAwardsView2(nav));
nav.setEditAwards3(new EditAwardsView3(nav));
nav.setAccountUpdate(new AccountUpdateView(nav));
nav.setYouthMemberList(new YouthMemberListView(nav));
nav.setScoutAward(new ScoutAwardView(nav));
nav.setAwardStock(new AwardStockView(nav));
RootPanel.get().add(new LoginView(nav));
}
}
package org.AwardTracker.client;
/**
* The purpose of this package is to define the
* widgets that make up the Award Tracker views.
* If you add a view here also update AwardTracker.java.
*/
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
public class NavHandler {
private RootPanel rootPanel;
private Widget login;
private Widget createAccount;
private Widget updateAccount;
private Widget selectPerson;
private Widget awardOverview;
private Widget awardGroup;
private Widget editYouthMember;
private Widget editAwards1;
private Widget editAwards2;
private Widget editAwards3;
private Widget accountUpdate;
private Widget youthMemberList;
private Widget scoutAward;
private Widget awardStock;
public NavHandler(RootPanel rootPanel2) {
this.rootPanel = rootPanel2;
}
public void go(String code) {
rootPanel.clear();
RootPanel.get().clear();
login.removeFromParent();
createAccount.removeFromParent();
updateAccount.removeFromParent();
selectPerson.removeFromParent();
awardOverview.removeFromParent();
awardGroup.removeFromParent();
editYouthMember.removeFromParent();
editAwards1.removeFromParent();
editAwards2.removeFromParent();
editAwards3.removeFromParent();
accountUpdate.removeFromParent();
youthMemberList.removeFromParent();
scoutAward.removeFromParent();
awardStock.removeFromParent();
if (code.equalsIgnoreCase("Login")){
rootPanel.add(login);
}else if (code.equalsIgnoreCase("CreateAccount")){
rootPanel.add(createAccount);
}else if (code.equalsIgnoreCase("UpdateAccount")){
rootPanel.add(updateAccount);
}else if (code.equalsIgnoreCase("SelectPerson")){
rootPanel.add(selectPerson);
}else if (code.equalsIgnoreCase("AwardOverview")){
rootPanel.add(awardOverview);
}else if (code.equalsIgnoreCase("AwardGroup")){
rootPanel.add(awardGroup);
}else if (code.equalsIgnoreCase("EditYouthMember")){
rootPanel.add(editYouthMember);
}else if (code.equalsIgnoreCase("EditAwards1")){
rootPanel.add(editAwards1);
}else if (code.equalsIgnoreCase("EditAwards2")){
rootPanel.add(editAwards2);
}else if (code.equalsIgnoreCase("EditAwards3")){
rootPanel.add(editAwards3);
}else if (code.equalsIgnoreCase("AccountUpdate")){
rootPanel.add(accountUpdate);
}else if (code.equalsIgnoreCase("YouthMemberList")){
rootPanel.add(youthMemberList);
}else if (code.equalsIgnoreCase("ScoutAward")){
rootPanel.add(scoutAward);
}else if (code.equalsIgnoreCase("AwardStock")){
rootPanel.add(awardStock);
}
}
public void setLogin(Widget view) {
login = view;
}
public void setNewAccount(Widget view) {
createAccount = view;
}
public void setUpdateAccount(Widget view) {
updateAccount = view;
}
public void setSelectPerson(Widget view) {
selectPerson = view;
}
public void setAwardOverview(Widget view) {
awardOverview = view;
}
public void setAwardGroup(Widget view) {
awardGroup = view;
}
public void setEditYouthMember(Widget view) {
editYouthMember = view;
}
public void setEditAwards1(Widget view) {
editAwards1 = view;
}
public void setEditAwards2(Widget view) {
editAwards2 = view;
}
public void setEditAwards3(Widget view) {
editAwards3 = view;
}
public void setAccountUpdate(Widget view) {
accountUpdate = view;
}
public void setYouthMemberList(Widget view) {
youthMemberList = view;
}
public void setScoutAward(Widget view) {
scoutAward = view;
}
public void setAwardStock(Widget view) {
awardStock = view;
}
}
按钮返回“SelectPerson”视图:
//Add each button to the horizontal panel.
btnSelectYM.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
navHandler2.go("SelectPerson");
}
});
btnSelectYM.setStyleName("gwt-PushButton-up");
btnSelectYM.setText("Select Youth Member");
btnSelectYM.setWidth("184px");
btnSelectYM.setHeight("40px");
horizontalPanel.add(btnSelectYM);
答案 0 :(得分:0)
尝试使用Widget#removeFromParent()从其父窗口小部件中移除此窗口小部件(如果存在)。
使用
AwardOverview.removeFromParent();
而不是
rootPanel.remove(AwardOverview);
OR
尝试删除所有子窗口小部件的Panel#clear()。
RootPanel.get().clear();'
OR
尝试清除rootPanel的RootPanel#clear(boolean)。如果clearDom为true,则还删除任何不是小部件的DOM元素。
注意:尊重Java Naming Convention。