I have an abstract controller support class for searches and result lists:
@Controller
@SessionAttributes("query")
public abstract class SearchController<Q extends SearchQuery> {
@RequestMapping
public String performSearch(@ModelAttribute("query") Q query) {
....
}
@ModelAttribute("query")
public abstract Q createDefaultSearchQuery();
}
Several real-world search controllers extend this base class.
After accessing one of the controllers (for example, /searchBooks.htmlusing BookSearchQuery implements SearchQuery), the request will be correctly saved in the session, available for subsequent requests.
However, when I access another controller (for example, /searchAuthors.htmlusing AuthorSearchQuery implements SearchQuery), the request from the last request ( BookSearchQuery) is still used for the new controller, which will ClassCastExceptionbe called later.
I tried moving the annotation @SessionAttributefrom the support class to the implementation classes, but to no avail.
-, ? ?
!