我正在升级我们的网络应用程序以使用Wicket 7(使用6.19)。
第一页是登录屏幕,但由于某种原因,表单的onSubmit()
方法未被调用,因此单击提交按钮时,我只是重新显示登录页面。
我咨询了Wicket 7 migration guide,但未提及此领域的任何具体变化。
这是一个非常简单的案例,正如您所看到的,它是一个包含用户名和密码字段的简单表单
<form wicket:id="loginform" id="loginform" >
<table style="display: table; border: 0px; margin: auto;">
<tr style="display: table-row;">
<td class="login" colspan="2"><span wicket:id="feedback">Feedback</span></td>
</tr>
<tr style="display: table-row;">
<td class="login">
<label for="username"><wicket:message key="username">Username</wicket:message>: </label>
</td>
<td class="login">
<input wicket:id="username" id="username" type="text" name="user" value="" size="30" maxlength="50"/>
</td>
</tr>
<tr style="display: table-row;">
<td class="login">
<label for="password"><wicket:message key="password">Password</wicket:message>: </label>
</td>
<td class="login">
<input wicket:id="password" id="password" type="password" name="pswd" value="" size="30" maxlength="16"/>
</td>
</tr>
<tr style="display: table-row;">
<td class="login"> </td>
<td class="login"><input class="btn" type="submit" name="Login" value="Login" wicket:message="title:loginButtonTitle"/></td>
</tr>
</table>
</form>
这是设置页面组件的Java代码 -
public class Login extends UnSecurePageTemplate {
private static final long serialVersionUID = -7202246935258483555L;
@SpringBean private IBrandingService brandingService;
@SpringBean private IRemonService remonService;
@SpringBean private IUserAdminService userAdminService ;
private static final Logger logger = LoggerFactory.getLogger( Login.class);
public Login() {
this(new PageParameters());
}
public Login(PageParameters pageParameters) {
super(pageParameters);
BrandingThemeProperties properties = brandingService.getBrandingThemeProperties();
String welcomeLabel = properties.getProperty("welcome-label");
add(new Label("welcome", welcomeLabel));
add(new Label("loginHeader", getStringFromPropertiesFile("loginInstruction", this)));
LoginForm form = new LoginForm("loginform", new SimpleUser(), pageParameters);
form.add(new FeedbackPanel("feedback"));
add(form);
}
这是登录表单(login()
方法验证用户并返回另一页) -
public final class LoginForm extends Form<SimpleUser>
{
PageParameters pageParameters;
public LoginForm(String id, SimpleUser simpleUser, PageParameters pageParameters)
{
super(id, new CompoundPropertyModel<SimpleUser>(simpleUser));
this.pageParameters = pageParameters;
add(new TextField<String>("username").setRequired(true).add(StringValidator.maximumLength(50)));
add(new PasswordTextField("password").setResetPassword(true).add(StringValidator.maximumLength(50)));
}
/**
* Called upon form submit. Attempts to authenticate the user.
*/
protected void onSubmit()
{
SimpleUser user = getModel().getObject();
String username = user.getUsername();
String password = user.getPassword();
login(username, password, pageParameters);
}
}
我也尝试使用提交按钮,但其onSubmit()
也未被调用。