Hi!
I'm newbie in Spring MVC, and i have a problem that making me crazy!
I have a form with a <select> multiple (the values of a Collection), but when i view the database, there are all the fields of the class, but not the Collection. My code is this:
Bean: Libro, parent of the relationship
Code:public class Libro { private Long isbn; private String titulo = ""; ....... private Set<Autor> autores = null; }
Bean: Autor, childs
Controller: AdminLibroRegisterFormControllerCode:public class Autor { private String apellidoPaterno = ""; private String apellidoMaterno = ""; private String nombres = ""; private Long id; }
Support for Autor: AutorSupportCode:public class AdminLibroRegisterFormController extends AbstractWizardFormController { ..... protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(Autor.class, new AutorSupport()); } ..... }
Code:public class AutorSupport extends PropertyEditorSupport { private ICatalogoService catalogoService; ..... public void setAsText(String string) throws IllegalArgumentException { try { Long id = Long.valueOf(string); Autor a = catalogoService.findAutorById(id); if(a==null){ throw new IllegalArgumentException("Id de Autor Inválido"); } setValue(a); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Invalid id for Autor: " + string); } } ..... }
JSP Page
Code:.... <tr> <th><label for="autor" class="required"> * <fmt:message key="libro.autor" />:</label></th> <td><spring:bind path="libro.autores"> <select name="autor" multiple> <c:forEach var="autor" items="${autores}"> <option value="<c:out value="${autor.id}"/>"><c:out value="${autor.nombres} ${autor.apellidoPaterno} ${autor.apellidoMaterno}" /></option> </c:forEach> </select> </spring:bind></td> </tr> ....
Help me please!!!!!


Reply With Quote
I understand the problem now ! I will fix it now jejeje
