I am trying to get a list of selected candidates to my controller using @modelAttribute with their respective id and blurb. I am able to bring one Candidate correctly but i don't know how to bring a list of candidates thru... I tried to add List<> as i have shown below, but i get
ERROR - SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/panel-requests] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface
JSP -
<form:form modelAttribute="candidateAddAttribute"
action="/panel-requests/requests/${panelRequestForId.id}/empl" method="post">
<c:forEach items="${candidates}" var="candidates">
<select name="employee" id="employee" disabled="disabled">
<option value="default" selected="selected">${candidates.candidateName}</option>
</select>
<textarea rows="3" cols="40" id="candidateBlurb" name="candidateBlurb"
disabled="disabled">${candidates.candidateBlurb}</textarea>
<textarea rows="2" cols="20" id="candidateCV" name="candidateCV"
disabled="disabled">${candidates.candidateCV}</textarea>
</c:forEach>
<div id="candidateDiv" id="candidateDiv">
<select name="employee" id="employee">
<option value="default" selected="selected">Select Employee</option>
<c:forEach items="${employees}" var="employee">
<option value="${employee.id}" id="${employee.id}">
${employee.employeeName}- ${employee.employeeCV}<
/option>
</c:forEach>
</select>
<textarea rows="3" cols="40" id="candidateBlurb"
name="candidateBlurb">BLURB</textarea>
<div id="employeeCv"></div>
<input type="submit" value="Add Candidate" />
</div>
</form:form>
The above form at first displays list of employee and when user selects employee, enters blurb and hits add candidate button, i take data to controller.
Controller:
@RequestMapping(value = "{id}/empl", method = RequestMethod.POST)
public String getEmployeeDetails(
@ModelAttribute("candidateAddAttribute") @Valid List<Candidate> candidates,
BindingResult result, @PathVariable("id") int requestId, Model model) {
//implementation goes here
}
How do I implement List in this case? Thanks in advance.
EDITED PART I tried sending 2 candidate's details, firebug sends it correctly like - Parameters candidateBlurb BLURB sar candidateBlurb BLURB dann employee 1 employee 2
so it can be a problem in initBinder that i ma using, binder.registerCustomEditor(Employee.class, new PropertyEditorSupport() { public String getAsText() { return Long.toString(((Employee) getValue()).getId()); }
public void setAsText(final String text) {
Employee employee = Employee.findById(Integer
.parseInt(text));
setValue(employee);
}
});
which only takes 1 employee detail at a time. Is that a problem here???