这是我的yesNoPanel
课程,扩展了Panel
:
public class YesNoPanel extends Panel {
/**
*
*/
private String password = "Password";
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private static final long serialVersionUID = -8356163236155431543L;
public String getPw()
{
String pw=ConfigurationHelper.getConfigurationProperty("REFRESH_CACHE_PASSWORD", "");
return pw;
}
public YesNoPanel(String id, String message, final ModalWindow modalWindow, final ConfirmationAnswer answer) {
super(id);
final Form yesNoForm = new Form("yesNoForm");
final String wrongPw = "Wrong Password";
final TextField<String> passwordString = new RequiredTextField<String>("password", new PropertyModel(this, password));
passwordString.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
MultiLineLabel messageLabel = new MultiLineLabel("message", message);
yesNoForm.add(messageLabel);
final Label wrongPW = new Label("WrongPassword", wrongPw );
modalWindow.setTitle("Please confirm");
modalWindow.setInitialHeight(200);
modalWindow.setInitialWidth(350);
AjaxButton yesButton = new AjaxButton("yesButton", yesNoForm) {
private static final long serialVersionUID = -3827487963204274386L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (target != null && password.equals(getPw())) {
answer.setAnswer(true);
modalWindow.close(target);
}else if(target != null && !password.equals(getPw())){
answer.setAnswer(false);
wrongPW.setVisible(true);
target.add(wrongPW);
}
}
};
AjaxButton noButton = new AjaxButton("noButton", yesNoForm) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (target != null) {
answer.setAnswer(false);
modalWindow.close(target);
wrongPW.setVisible(false);
}
}
};
yesNoForm.add(yesButton);
yesNoForm.add(noButton);
yesNoForm.add(passwordString);
add(yesNoForm);
wrongPW.setOutputMarkupPlaceholderTag(true);
wrongPW.setVisible(false);
add(wrongPW);
}
}
和有问题的HTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:wicket>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
</head>
<body>
<wicket:panel>
<form wicket:id="yesNoForm" action="">
<span wicket:id="message">Are you sure?</span>
<table style="width: 65%;" align="center">
<tr>
<td align="left">
<input type="submit" wicket:id="noButton" value="No" />
</td>
<td align="right">
<input type="text" wicket:id="password" size = "20" />
</td>
<td align="right">
<input type="submit" wicket:id="yesButton" value="Yes" />
</td>
</tr>
</table>
</form>
<font color="red"><p align="center" wicket:id="WrongPassword"></p> </font>
</wicket:panel>
</body>
就像现在一样,当用户打开模态窗口时,输入框中会填充wicket id password
- 这就是字符串“Password”。如果输入留空(或使用占位符,这是首选),Yes
或No
按钮不会执行任何操作。为什么会这样,我该如何解决呢?
答案 0 :(得分:2)
您应该使用TextField而不是RequiredTextField。 使用带有空白输入的RequiredTextField,按钮不会执行任何操作。