Error 400 “The request sent was syntactically incorrect” Spring

0

Witam mam problem z przesyłaniem formularza korzystając z Spring MVC i Hibernatea. Przy przesłaniu formularza dostaje taki oto wynik.

type Status report

message

description The request sent by the client was syntactically incorrect.

Czy ktoś wie czym to może być spowodowane? Już zaczęło mi linków w google brakować :/

Niżej zamieszczam kod i błąd, który wyrzuca tomcat.

Kontroler:

 
@RequestMapping(value = { "/dodajregiony" }, method = RequestMethod.GET)
    public String newRegion(ModelMap model) {
        Region region = new Region();
        model.addAttribute("region", region);
        return "dodajregion";
    }


    @RequestMapping(value = { "/dodajregiony" }, method = RequestMethod.POST)
    public String saveRegion(@ModelAttribute("region") Region region, BindingResult result, Model model) {

        if (result.hasErrors()) {
            return "dodajregion";
        }

        serviceRegion.saveRegion(region);

        model.addAttribute("success", "Region " + region.getNazwa() + " dodany prawidłowo");
        return "success";
    }

Model:

 
@Entity
@Table(name="regiony")
public class Region {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_regionu")
    private int id;

    @NotNull
    @Size(max = 200)
    private String nazwa;

    @NotNull
    @Size(max = 500)
    private String krotkiOpis;

    private String opis;

    private int id_grupy;

    private String wojewodztwo;

    private int ocena;

    private int autor;

    private int aktywowany;

    @OneToMany(mappedBy = "region1",fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Aktualnosc> aktualnosci;

    @OneToMany(mappedBy = "region",fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<Atrakcja> atrakcje;

    //settery i gettery 

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Region region = (Region) o;
        return id == region.id && Objects.equals(nazwa, region.nazwa);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, nazwa);
    }

    @Override
    public String toString() {
        return "Region{" +
                "id=" + id +
                ", nazwa='" + nazwa + '\'' +
                '}';
    }

}

Widok:

<form:form method="POST" modelAttribute="region">
                <form:input type="hidden" path="id" id="id"/>
                <form:input type="hidden" path="id_grupy" id="id_grupy"/>
                <form:input type="hidden" path="ocena" id="ocena"/>
                <form:input type="hidden" path="autor" id="autor"/>
                <form:input type="hidden" path="aktywowany" id="aktywowany"/>

                <fieldset class="form-group">
                    <label for="nazwa">Nazwa</label>
                    <form:input type="text" path="nazwa" class="form-control" id="nazwa" placeholder="Wprowadź nazwę" />
                    <div class="has-error">
                        <form:errors path="nazwa" class="help-inline"/>
                    </div>
                </fieldset>
                <fieldset class="form-group">
                    <label for="krotkiOpis">Krótki opis</label>
                    <form:textarea class="form-control" path="krotkiOpis" rows="3" id="krotkiOpis" placeholder="Wprowadź krótki opis" />
                    <small class="text-muted">Krótki opis powinień zawierać max. 500 znaków</small>
                    <div class="has-error">
                    <form:errors path="krotkiOpis" class="help-inline"/>
                    </div>
                </fieldset>
                <fieldset class="form-group">
                    <label for="opis">Opis</label>
                    <form:textarea class="form-control opisTextarea" path="opis" rows="13" id="opis" placeholder="Wprowadź opis" />
                    <div class="has-error">
                    <form:errors path="opis" class="help-inline"/>
                    </div>
                </fieldset>
                <fieldset class="form-group">
                    <label for="wojewodztwo">Wybierz województwo</label>
                    <form:select class="form-control" path="wojewodztwo" id="wojewodztwo">
                        <option>Dolnoślaskie</option>
                        <option>Kujawsko-pomorskie</option>
                        <option>Lubelskie</option>
                        <option>Lubuskie</option>
                        <option>Łódzkie</option>
                        <option>Małopolskie</option>
                        <option>Mazowieckie</option>
                        <option>Opolskie</option>
                        <option>Podkarpackie</option>
                        <option>Podlaskie</option>
                        <option>Pomorskie</option>
                        <option>Śląskie</option>
                        <option>Świętokrzyskie</option>
                        <option>Warmińsko-mazurskie</option>
                        <option>Wielkopolskie</option>
                        <option>Zachodniopomorskie</option>
                    </form:select>
                    <div class="has-error">
                    <form:errors path="wojewodztwo" class="help-inline"/>
                    </div>

                </fieldset>
                
                        <button type="submit" class="btn btn-primary">Dodaj region</button>
                    
            </form:form>
 

I błąd, który wyrzuca tomcat:

09-Jan-2016 01:11:51.873 WARNING [http-nio-8080-exec-8] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleTypeMismatch Failed to bind request element: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'pl.travel.tourist.model.Region' to required type 'pl.travel.tourist.model.Region'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type pl.travel.tourist.model.Region to type @org.springframework.web.bind.annotation.ModelAttribute pl.travel.tourist.model.Region for value 'Region{id=0, nazwa='dsfa asd fasd fasd as dfa'}'; nested exception is java.lang.ClassCastException: pl.travel.tourist.model.Region cannot be cast to java.lang.String
 

Czy byłby ktoś w stanie pomóc, nakierować na jakieś rozwiązanie?

1
  1. Podaj jakis link do repo bo błąd pewnie jest w kodzie którego nie widzimy...
  2. Używanie klas encyjnych jako beanów do formularzy to jest bardzo zły pomysł i może generować trudne do wyśledzenia błędy.

1 użytkowników online, w tym zalogowanych: 0, gości: 1