Announcement Announcement Module
No announcement yet.
JSP + Rest +ManyToOne = error 400 Bad Request Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSP + Rest +ManyToOne = error 400 Bad Request

    Hi to all,

    I'm trying to submit a form for an entity that has a ManyToOne relationship.

    When I click to submit I receive error 400 Bad Request, but when I comment in my JSP the part of relationship the submit works ok. The attribute path in the form is pointing correctly to the relationship

    Here part of my Entity:

    @Table(schema="sgn", name="prospect")
    public class Prospect implements Serializable {
    	private static final long serialVersionUID = 1L;
    //bi-directional many-to-one association to TipoProposta
    	@JoinColumn(name="id_tipo_proposta", insertable=false, updatable=false)
    	private TipoProposta tipoProposta;
    Here the part of Controller

    public class ProspectController {
    @RequestMapping(value = "/Demanda/teste", method = RequestMethod.POST)
    	public String create(@ModelAttribute("prospect") Prospect prospect) {
    		return "redirect:/Demanda/list";
    	protected void initBinder(WebDataBinder binder) throws Exception {
    		binder.registerCustomEditor(List.class, "tipoProposta",
    				new CustomCollectionEditor(List.class) {
    					protected Object convertElement(Object element) {
    						if (element instanceof TipoProposta) {
    							return element;
    						if (element instanceof String) {
    							return tipoPropostaRepository.findOne(Long
    						return null;
    Here the part of JSP

    <c:url value="/Demanda/teste" var="teste"/>
    		<form:form method="POST" commandName="prospect" action="${teste}" cssClass="form-horizontal" name="form_prospect_registro" acceptCharset="UTF-8">
    			<form:hidden path="id" />
    <form:select id="selectTipoProposta" cssClass="span2" name="proposta_tipo" path="tipoProposta">
    		        		<c:forEach items="${listaTipoProposta}" var="tp" varStatus="i">
    				       			 <c:when test="${ == prospectHasTipoProposta[i.index].id}">
    				            		<form:option selected="selected" value="${}">
    				                		<c:out value="${tp.descricao}"/>
    						            <form:option value="${}">
    						                <c:out value="${tp.descricao}"/>
    Please, can someone help me?

  • #2
    Why do people keep writing those ugly constructs?! Read the documentation...

    <form:select cssClass="span2" path="tipoProposta" items="listaTipoProposata" itemValue="id" itemLabel="descricao"/>
    This (from the top of my head) should more or less do what you want. Your id and/or name attribute breaks proper binding.

    Also I don't really see how this is related to REST as there isn't much REST in your sample... Just a normal plain form submit...


    • #3
      Thanks for your help.

      I also tried to do in this way, but I get the same error. Please look what happenes when I submit the page


      • #4
        I know what happens en the problem, AFAIK, is in the definition of your select element. Not sure if my version works as I typed it from the top of my head.

        Enable DEBUG or TRACE logging on your application and check what is happening.