[英]Refresh Component of Parent Page on Modal Window closing
I have a modal window, simulation JavaScript confirm box. 我有一个模态窗口,模拟JavaScript确认框。 Depending on button click ie, 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? 我怎样才能做到这一点?
I have solved the problem. 我已经解决了问题。 I am giving the solution so that it may help future users.
我正在提供解决方案,以便它可能对将来的用户有所帮助。 The modal window page is :
模态窗口页面为:
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);
}
});
}
}
}
Here the ParentPage is the page from which the modal window is generated. 此处的ParentPage是从其生成模式窗口的页面。 In the ParentPage I have a field isCancelButtonClicked and its getter and setter.
在ParentPage中,我有一个字段isCancelButtonClicked及其getter和setter。 In that page I have set
在该页面中,我已设置
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);
}
}
});
And voilà. 还有。 Thanks.
谢谢。
You'll probly have better luck if you use wicket models instead of javascript. 如果您使用检票口模型而不是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);
}像这样:
@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);
}@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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.