Ao submeter o meu form, surge um erro devido a este trecho:
<select name="departamento" style=" width : 354px;"> <c:forEach var="departamento" items="$ {allDepts}"> <option value="$ {departamento.selfId}" $ {especialidade.departamento==departamento.selfId ?'selected' :''}> $ {departamento.designacao} </option> </c:forEach> </select>
Field error in object ‘especialidadeVO’ on field ‘departamento’: rejected value [0]; …….no matching editors or conversion strategy found]. Salientar que na minha classe Modelo EspecialidadeVO tenho o DepartamentoVo como atributo não primitivo, ou seja DepartamentoVo é tb uma classe.
Classe EspecialidadeVO: package iim.sigra.model.especialidade; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import iim.sigra.model.departamento.DepartamentoVO; @Entity @Table(name = "ESPECIALIDADE") public class EspecialidadeVO implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator="increment") @GenericGenerator(name="increment", strategy = "increment") protected long selfId; protected String designacao; protected String descricao; protected int duracaoNumSemestres; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="id_departamento") protected DepartamentoVO departamento; public long getSelfId() { return selfId; } public void setSelfId(long selfId) { this.selfId = selfId; } public String getDesignacao() { return designacao; } public void setDesignacao(String designacao) { this.designacao = designacao; } public String getDescricao() { return descricao; } public void setDescricao(String descricao) { this.descricao = descricao; } public int getDuracaoNumSemestres() { return duracaoNumSemestres; } public void setDuracaoNumSemestres(int duracaoNumSemestres) { this.duracaoNumSemestres = duracaoNumSemestres; } public DepartamentoVO getDepartamento() { return departamento; } public void setDepartamento(DepartamentoVO departamento) { this.departamento = departamento; } } Classe DepartamentoVo: package iim.sigra.model.departamento; import java.io.Serializable; import java.util.Collection; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import iim.sigra.model.especialidade.EspecialidadeVO; @Entity @Table(name = "DEPARTAMENTO") public class DepartamentoVO implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator="increment") @GenericGenerator(name="increment", strategy = "increment") protected long selfId; protected String designacao; protected String descricao; @OneToMany(mappedBy="departamento", fetch = FetchType.LAZY) protected Collection<EspecialidadeVO> especialidades; public long getSelfId() { return selfId; } public void setSelfId(long selfId) { this.selfId = selfId; } public String getDesignacao() { return designacao; } public void setDesignacao(String designacao) { this.designacao = designacao; } public String getDescricao() { return descricao; } public void setDescricao(String descricao) { this.descricao = descricao; } } Controller EspecialidadeAction: package iim.sigra.controller.especialidade; import java.util.ArrayList; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import iim.sigra.model.departamento.DepartamentoDAO; import iim.sigra.model.departamento.DepartamentoVO; import iim.sigra.model.especialidade.EspecialidadeDAO; import iim.sigra.model.especialidade.EspecialidadeVO; import iim.sigra.model.pessoa.usuario.UsuarioVO; import iim.sigra.utilitarios.Mensagens; @Controller @RequestMapping("/especialidade") public class EspecialidadeAction { ArrayList<EspecialidadeVO> allEspecialidades = new ArrayList<EspecialidadeVO>(); @RequestMapping(method=RequestMethod.GET) public ModelAndView step0(){ ModelAndView modelView = new ModelAndView("/especialidade/especialidade-form"); ArrayList<DepartamentoVO> allDepts = new ArrayList<DepartamentoVO>(); allDepts.add(0, new DepartamentoVO()); DepartamentoDAO deptDao = new DepartamentoDAO(); allDepts.addAll(deptDao.getAll()); modelView.addObject("allDepts", allDepts); EspecialidadeDAO espcDao = new EspecialidadeDAO(); this.allEspecialidades=espcDao.getAll(); modelView.addObject("allEspecialidades", this.allEspecialidades); return modelView; } @RequestMapping(value="/save", method= {RequestMethod.POST}) public ModelAndView save (EspecialidadeVO especialidade, UsuarioVO user, Model model) throws Exception{ System.out.println("Salvando.......!"); EspecialidadeDAO espDao = new EspecialidadeDAO(); espDao.save(especialidade,user); model.addAttribute("statusMsg", Mensagens.OPERATION_SUCCESS_MSG); return new ModelAndView("/especialidade/especialidade-form", "allEspecialidades", this.allEspecialidades) ; } }