模态窗口关闭时刷新父页面组件
我有一个模态窗口,模拟JavaScript确认框。根据按钮单击,即取消按钮或确定按钮,我想刷新父页面的某些组件。但不幸的是它不起作用。正如您从代码中看到的,我想将两个文本字段的值设置为“”,隐藏面板并将下拉列表的选定选项设置为零。这并没有发生,组件仍未刷新。
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);
}
});
}
}
}
我该怎么做?
I have a modal window, simulation JavaScript confirm box. Depending on button click i.e., cancel button or ok button I want to refresh some component of the parent page. But unfortunately it is not working. As you can see from the code, I want to set values to the two textfields to "", hide a panel and set selected option of dropdown to zero. This is not happening, the components are remaining unrefreshed.
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);
}
});
}
}
}
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经解决了这个问题。我给出解决方案,以便它可以帮助未来的用户。
模式窗口页面是:
这里的 ParentPage 是生成模式窗口的页面。在 ParentPage 中,我有一个字段 isCancelButtonClicked 及其 getter 和 setter。在该页面中我设置了
瞧。谢谢。
I have solved the problem. I am giving the solution so that it may help future users.
The modal window page is :
Here the ParentPage is the page from which the modal window is generated. In the ParentPage I have a field isCancelButtonClicked and its getter and setter. In that page I have set
And voilà. Thanks.
如果您使用 wicket 模型而不是 javascript,您可能会有更好的运气。像这样的东西:
<代码>
@覆盖
protected void onSubmit(AjaxRequestTarget target, Form form) {
// 我正在尝试刷新此处的组件
userAssignmentInfoPanel.setVisible(false);
target.add(userAssignmentInfoPanel);
choice.getModelObject().setSelected(0);
target.add(选择);
ScheduledTimeField.setModelObject("");
deadLineField.setModelObject("");
target.add(scheduledTimeField);
target.add(deadLineField);
}
You'll probly have better luck if you use wicket models instead of javascript. Something like this:
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
// I am trying to refresh the component here
userAssignmentInfoPanel.setVisible(false);
target.add(userAssignmentInfoPanel);
choice.getModelObject().setSelected(0);
target.add(choice);
scheduledTimeField.setModelObject("");
deadLineField.setModelObject("");
target.add(scheduledTimeField);
target.add(deadLineField);
}