gpt4 book ai didi

java - Wicket - 当值为空时提交按钮功能出现问题

转载 作者:行者123 更新时间:2023-12-02 03:44:51 25 4
gpt4 key购买 nike

这是我的 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”。如果输入留空(或者使用占位符,这是更好的选择),YesNo 按钮不会执行任何操作。这是为什么?我该如何解决这个问题?

最佳答案

您应该使用 TextField 而不是RequiredTextField。使用带有空白输入的RequiredTextField,按钮不会执行任何操作。

关于java - Wicket - 当值为空时提交按钮功能出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36407419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com