检票口虚拟表格字段
我尝试为用户制作使用 Wicket 注册的表格。我得到了用户 POJO 和 wicket 表单 - 这需要有“重复密码”字段,该字段不应以任何方式连接到 User 对象。但我该怎么做呢?我
public class RegisterForm extends Form<User> {
private static final long serialVersionUID = -9071906666130179515L;
public RegisterForm(String id) {
super(id, new CompoundPropertyModel<User>(new User()));
PasswordTextField pass = new PasswordTextField("password");
pass.setType(String.class);
PasswordTextField pass2 = new PasswordTextField("password2");
pass2.setType(String.class);
pass2.setDefaultModelObject("");
add(new EqualPasswordInputValidator(pass, pass2));
add(new TextField<String>("login")
.setType(String.class)
.setRequired(true)
.add(new PatternValidator("[a-z0-9]*")));
add(new TextField<String>("email")
.setType(String.class)
.add(EmailAddressValidator.getInstance()));
add(pass);
add(pass2);
}
但我明白了
java.lang.IllegalStateException: 尝试将模型对象设置为 null 组件型号:
或者 User 模型没有与password2相关的方法。遇到这样的情况该如何处理呢?
I try to make form for user to register using Wicket. I got user POJO and wicket form - this needs to have "repeat password" field which should be in no way connected to User object. But how can I do this? I
public class RegisterForm extends Form<User> {
private static final long serialVersionUID = -9071906666130179515L;
public RegisterForm(String id) {
super(id, new CompoundPropertyModel<User>(new User()));
PasswordTextField pass = new PasswordTextField("password");
pass.setType(String.class);
PasswordTextField pass2 = new PasswordTextField("password2");
pass2.setType(String.class);
pass2.setDefaultModelObject("");
add(new EqualPasswordInputValidator(pass, pass2));
add(new TextField<String>("login")
.setType(String.class)
.setRequired(true)
.add(new PatternValidator("[a-z0-9]*")));
add(new TextField<String>("email")
.setType(String.class)
.add(EmailAddressValidator.getInstance()));
add(pass);
add(pass2);
}
But i get
java.lang.IllegalStateException:
Attempt to set model object on null
model of component:
or that User model has no password2 related methods. How to handle such a case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以做到:
解释:
CompoundPropertyModel
将嵌套表单元素与父模型关联起来(组件名称foo
映射到的bean.foo
属性父模型)。您可以通过为子组件分配不同的模型来覆盖此行为。This should do it:
Explanation:
CompoundPropertyModel
associates nested form elements with the parent model (component namefoo
is mapped to thebean.foo
property of the parent model). You can overwrite this behavior by assigning a different model to the child component.我会使用表单中的属性和
PropertyModel
。这样我就可以通过 getPassword2() 方法访问该字段。I would have used a property in the form and a
PropertyModel
. This way I would have access to the field throught thegetPassword2()
method.