我正在尝试将searchService传递到Wicket的Form中使用。当我在searchService是最终版本的情况下运行此程序时,我没有任何问题,但是我必须使其最终版本才能在覆盖的onSubmit中使用它。
final SearchService searchService = new SearchService();
Form<?> form = new Form("searchForm") {
public void onSubmit() {
List<File> results = searchService.getSearchResults();
info("Found: " + results.size());
}
};
如果这样做,我会收到一个错误:
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: The object type is not Serializable!
A problem occurred while checking object with type: test.service.SearchService
Field hierarchy is:
2 [class=test.webui.HomePage, path=2]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
private java.lang.Object org.apache.wicket.MarkupContainer.children[1] [class=org.apache.wicket.markup.html.form.Form, path=2:searchForm]
private final test.service.SearchService test.webui.HomePage$1.val$searchService [class=test.service.SearchService] <----- field that is causing the problem
我是wicket的新手,所以我想知道是否有正确的方法来做到这一点?
是。这是预期的行为。
Wicket将序列化整个页面。实际上,整个页面流。
您看到的错误非常好,因为它可以帮助您使应用程序在复制的会话群集中工作。
要解决它,您有几种选择。在我的头顶上:
您可以尝试将Serializable
实现到您的SearchService
类并声明一个变量serialVersionUID
。
例如:
public class SearchService implements Serializable {
private static final long serialVersionUID = -1769512858853931584L;
//your code
}