我面临以下问题:
我有带过滤器的检票口页面。Filter 是包含这个 TextField 的表单组件:
TextField<Long> categoryField = new TextField<Long>("categoryId",
BindingModel.of(model, binding.categoryId()),
Long.class);
add(categoryField );
我想让用户记住他最后的过滤器选项,所以我将字段值存储在 cookie 中
CookieUtils utils = new CookieUtils();
utils.save(categoryField);
这工作正常,字段值存储在 cookie 中。但问题是当我想从 cookie 中读取值并将其设置为组件时
utils.load(categoryField);
然后我得到:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
at cz.myproject.domain.MyFilterBindingPath$CategoryIdBinding.setWithRoot(MyFilterBindingPath.java:494)
at cz.myproject.binding.BindingModel.setObject(BindingModel.java:66)
at org.apache.wicket.Component.setDefaultModelObject(Component.java:3061)
at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1560)
at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1104)
at org.apache.wicket.markup.html.form.FormComponent.setModelValue(FormComponent.java:1046)
at org.apache.wicket.util.cookies.CookieUtils.load(CookieUtils.java:135)
谢谢你的帮助