I am trying to pass a searchService into a Form into Wicket to use. When I run this with out the searchService being final I get no issues but I have to make it final in order to use it inside the overwritten onSubmit.
final SearchService searchService = new SearchService();
Form<?> form = new Form("searchForm") {
public void onSubmit() {
List<File> results = searchService.getSearchResults();
info("Found: " + results.size());
}
};
If I do that I receive an error:
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
I'm new to wicket so I'm wondering if there is a correct way to do this?
Yes. It is expected behavior.
Wicket will serialize the whole page. In fact, the whole pageflow.
The error you are seeing is great because it helps you make your application work in a replicated session cluster.
To solve it you have several options. Off the top of my head:
You can try to implement Serializable
to your SearchService
class and declare a variable serialVersionUID
.
Eg:
public class SearchService implements Serializable {
private static final long serialVersionUID = -1769512858853931584L;
//your code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.