Java 在模式窗口关闭时刷新父页面的组件
我有一个模态窗口,模拟JavaScript确认框。根据按钮单击,即“取消”按钮或“确定”按钮,我希望刷新父页面的某些组件。但不幸的是,它不起作用。正如您从代码中看到的,我想将两个文本字段的值设置为“”,隐藏一个面板,并将下拉菜单的选定选项设置为零。这不会发生,组件仍保持未刷新状态Java 在模式窗口关闭时刷新父页面的组件,java,wicket,Java,Wicket,我有一个模态窗口,模拟JavaScript确认框。根据按钮单击,即“取消”按钮或“确定”按钮,我希望刷新父页面的某些组件。但不幸的是,它不起作用。正如您从代码中看到的,我想将两个文本字段的值设置为“”,隐藏一个面板,并将下拉菜单的选定选项设置为零。这不会发生,组件仍保持未刷新状态 public class ModalConfirmWindow extends WebPage { private ModalWindow modalConfirmWindow; privat
public class ModalConfirmWindow extends WebPage {
private ModalWindow modalConfirmWindow;
private UserAssignmentInfoPanel userAssignmentInfoPanel;
private DropDownChoice choice;
private TextField scheduledTimeField;
private DateTextField deadLineField;
private int numberOfConflictingDays;
public ModalConfirmWindow(ModalWindow modalConfirmWindow, UserAssignmentInfoPanel userAssignmentInfoPanel, DropDownChoice choice, TextField scheduledTimeField, DateTextField deadLineField, int numberOfConflictingDays) {
this.modalConfirmWindow = modalConfirmWindow;
this.userAssignmentInfoPanel = userAssignmentInfoPanel;
this.choice = choice;
this.scheduledTimeField = scheduledTimeField;
this.deadLineField = deadLineField;
this.numberOfConflictingDays = numberOfConflictingDays;
add(new ModalConfirmWindowForm("form"));
}
private class ModalConfirmWindowForm extends Form {
private static final long serialVersionUID = 10090L;
public ModalConfirmWindowForm(String id) {
super(id);
add(new Label("value", " " + numberOfConflictingDays +" ").add(new SimpleAttributeModifier("style", "color: red")));
add(new AjaxButton("cancelButton", this) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
// I am trying to refresh the component here
String javaScript = "document.getElementById('"+ userAssignmentInfoPanel.getMarkupId() +"').display = 'none';" +
"document.getElementById('"+ choice.getMarkupId() +"').options[0].selected = 'selected';" +
"document.getElementById('"+ scheduledTimeField.getMarkupId() +"').value = \"\";" +
"document.getElementById('"+ deadLineField.getMarkupId() +"').value = \"\";";
//target.appendJavascript(javaScript);
//scheduledTimeField.add(new SimpleAttributeModifier("value", ""));
//target.addComponent(scheduledTimeField);
//modalConfirmWindow.close(target);
modalConfirmWindow.close(target);
target.appendJavascript(javaScript);
}
});
add(new AjaxButton("okButton", this) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
modalConfirmWindow.close(target);
}
});
}
}
}
我该怎么做呢?如果您使用wicket模型而不是javascript,您的运气肯定会更好。大概是这样的:
@覆盖
提交时受保护的void(AjaxRequestTarget目标,表单){
//我正在尝试刷新此处的组件
userAssignmentInfoPanel.setVisible(false);
target.add(userAssignmentInfoPanel);
choice.getModelObject().setSelected(0);
target.add(选项);
scheduledTimeField.setModelObject(“”;
deadLineField.setModelObject(“”;
target.add(scheduledTimeField);
target.add(死线字段);
}
我已经解决了这个问题。我给出解决方案是为了帮助未来的用户。
模式窗口页面为:
public class ModalConfirmWindow extends WebPage {
private Page parentPage;
private ModalWindow modalConfirmWindow;
private int numberOfConflictingDays;
public ModalConfirmWindow(Page parentPage, ModalWindow modalConfirmWindow, int numberOfConflictingDays) {
this.parentPage = parentPage;
this.modalConfirmWindow = modalConfirmWindow;
this.numberOfConflictingDays = numberOfConflictingDays;
add(new ModalConfirmWindowForm("form"));
}
private class ModalConfirmWindowForm extends Form {
private static final long serialVersionUID = 10090L;
public ModalConfirmWindowForm(String id) {
super(id);
add(new Label("value", " " + numberOfConflictingDays +" ").add(new SimpleAttributeModifier("style", "color: red")));
add(new AjaxButton("cancelButton", this) {
private static final long serialVersionUID = 10091L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
((ParentPage)parentPage).setCancelButtonClicked(true);
modalConfirmWindow.close(target);
}
});
add(new AjaxButton("okButton", this) {
private static final long serialVersionUID = 10092L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
((ParentPage)parentPage).setCancelButtonClicked(false);
modalConfirmWindow.close(target);
}
});
}
}
}
此处,ParentPage是生成模式窗口的页面。在ParentPage中,我有一个字段isCancelButtonClicked及其getter和setter。在那一页我已经设置好了
modalConfirmWindow.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
private static final long serialVersionUID = 10093L;
public boolean onCloseButtonClicked(AjaxRequestTarget target) {
ParentPage.this.isCancelButtonClicked = true;
return true;
}
});
modalConfirmWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
private static final long serialVersionUID = 10094L;
public void onClose(AjaxRequestTarget target) {
if (ParentPage.this.isCancelButtonClicked) {
String javascript = "document.getElementById('"+ scheduledTimeField.getMarkupId() +"').value = \"\";" +
"document.getElementById('"+ deadLineField.getMarkupId() +"').value = \"\";" +
"document.getElementById('"+ totalLabel.getMarkupId()+"').style.display = 'none';" +
"document.getElementById('"+ choice.getMarkupId() +"').options[0].selected = 'selected';" +
"document.getElementById('"+ choice.getMarkupId() +"').disabled = true;" +
"document.getElementById('"+ userAssignmentInfoPanel.getMarkupId() +"').style.display = 'none';";
target.appendJavascript(javascript);
}
}
});
瞧。谢谢。你能详细介绍一下“不工作”吗?@jzd我已经编辑了这篇文章以了解更多信息。谢谢。在我的情况下,我不能将userAssignmentInfoPanel或其他设置为可见(false),因为我的经验是,如果在组件上使用setVisible(false),则javascript无法使其可见。此页面的代码包含如下javascript.Component.setOutputMarkupPlaceholderTag(true);