I have a controller with the following:
@ModelAttribute("searchCriteria")
public abstract SearchableCommand searchCriteria();
@ModelAttribute("searchList")
public PaginatedListAdapter searchList() {
return new PaginatedListAdapter(defaultSortColumn, searchableService);
}
@RequestMapping
public String doSearch(
@ModelAttribute("searchCriteria") SearchableCommand searchableCommand,
Errors errors,
@RequestParam(value="sort", required=false) String sort,
@RequestParam(value="pageSize", required=false) Integer pageSize,
@RequestParam(value="dir", required=false) String dir,
@RequestParam(value="page", required=false) Integer page,
@ModelAttribute("searchList") PaginatedListAdapter searchList) {
//some logic here
};
And in my JSP I have the following for test purpose:
<form:form id="searchForm" commandName="searchCriteria">
<form:input path="searchCriteria[0].searchOperand"/>
<input id="submitButton" type="submit"/>
</form:form>
When submitting the form, I trace through my code and searchableCommand.getSearchCriteria[0] .setSearchOperand(...)
is called correctly. However once this is done I recieve the exception:
org.springframework.beans.NullValueInNestedPathException: Invalid property 'searchCriteria[0]' of bean class [com.domain.web.command.PaginatedListAdapter]: Cannot access indexed value of property referenced in indexed property path 'searchCriteria[0]': returned null
This because it is also trying to call PaginatedListAdapter.getSearchCriteria[0] .setSearchOperand(...)
. Co-incidentally this class also has a method called getSearchCriteria
, but regardless it makes no sense to me as to why spring is trying the bind the form post parameters to both @ModelAttribute
arguments, when my form explicitly states commandName="searchCriteria
for which only one @ModelAttribute
has that name.