我有一个模态窗口,模拟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);
}
});
}
}
}
我该怎么做呢?
2条答案
按热度按时间dced5bon1#
我已经解决了这个问题。我给出解决方案,以便它可以帮助未来的用户。模态窗口页面是:
这里的ParentPage是生成模态窗口的页面。在ParentPage中,我有一个字段isCancelButtonClicked及其getter和setter。
好了谢谢。
sz81bmfz2#
如果你使用wicket模型而不是javascript,你可能会有更好的运气。第一个月