Wicket:自动字段验证不起作用
我有一个整型字段,当我输入一个非整型值(比如一个符号值)时,反馈面板应该会自动触发默认消息,但它不起作用,我必须在form by method error()的onError方法中调用它 这是我使用的文本字段:Wicket:自动字段验证不起作用,wicket,Wicket,我有一个整型字段,当我输入一个非整型值(比如一个符号值)时,反馈面板应该会自动触发默认消息,但它不起作用,我必须在form by method error()的onError方法中调用它 这是我使用的文本字段: RequiredTextField<Integer> intField = new RequiredTextField<>("intValue", integerValue,Integer.class); 只有在我调用表单的方法onError(
RequiredTextField<Integer> intField =
new RequiredTextField<>("intValue", integerValue,Integer.class);
只有在我调用表单的方法onError()中的方法error()时,它才起作用。您能告诉我们如何创建表单和使用的模型吗?据我所知,您需要将模型绑定到字段。我最好的猜测是您的模型没有属性“intValue”
您可能想(重新)访问。我不确定您是如何设置模型的。一旦您添加了
RequiredTextField
,它将不允许您为空,并且由于您设置了Integer
类型,它将不允许输入字符
我已经尝试了一些代码片段,这些代码片段工作得很好,并且正在验证
HomePage.html
<html xmlns:wicket="http://wicket.apache.org">
<body>
<form wicket:id="someForm">
<div wicket:id="feedback"></div>
<input type="text" wicket:id="requiredText">
<input type="submit" value="submit">
</form>
</body>
</html>
请让我在你需要的情况下回复我的情况。请考虑使用一些标记来阅读可读性:所提供的信息不足以告诉你问题在哪里。请提供更多与此字段及其形式相关的代码。我想我已经找到了问题的原因,问题的原因是在我使用的模型中,我在库中使用了名为HibernateModel的自定义模型,该模型由我们公司创建,库名为wicketautodao,这是链接Nikolas,我不这么认为,因为如果模型没有属性“intValue”,它会抛出异常
<html xmlns:wicket="http://wicket.apache.org">
<body>
<form wicket:id="someForm">
<div wicket:id="feedback"></div>
<input type="text" wicket:id="requiredText">
<input type="submit" value="submit">
</form>
</body>
</html>
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
public HomePage(final PageParameters parameters) {
super(parameters);
Form form = new Form("someForm");
form.add(new FeedbackPanel("feedback"));
IModel integerValue= Model.of("");
form.add(new RequiredTextField("requiredText",integerValue,Integer.class));
add(form);
}
}