Nicht zu beheben ist: 'java.lang.String' , required Typ " java.util.Sammlung'
Ich bin immer diese Fehlermeldung, wenn ich meine form und kann nicht herausfinden, warum dies geschieht. Ich glaube, dass die taglib sollte der Umgang mit diesem. Ich habe versucht, den übergebenen Wert in meine jsp auf itemValue="id"
aber es hat keine Auswirkungen.
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'content' on field 'stateCollection': rejected value [com.myapp.cmt.model.State[ id=3 ]]; codes [typeMismatch.content.stateCollection,typeMismatch.stateCollection,typeMismatch.java.util.Collection,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [content.stateCollection,stateCollection]; arguments []; default message [stateCollection]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Collection' for property 'stateCollection'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type [com.myapp.cmt.model.State] for property 'stateCollection[0]': no matching editors or conversion strategy found]
Meine jsp
<strong>State</strong><br/>
<form:checkboxes path="stateCollection" items="${states}" itemLabel="name"/>
Meine Inhalte
public class Content implements Serializable {
.......
@JoinTable(name = "content_to_state", joinColumns = {
@JoinColumn(name = "content_id", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "state_id", referencedColumnName = "id")})
@ManyToMany
private Collection<State> stateCollection;
.....
@XmlTransient
public Collection<State> getStateCollection() {
return stateCollection;
}
public void setStateCollection(Collection<State> stateCollection) {
this.stateCollection = stateCollection;
}
.....
Mein Controller
...
@RequestMapping(value = "/{guid}/save", method = RequestMethod.POST)
public ModelAndView saveContent(@ModelAttribute("content") Content content, @PathVariable("guid") String guid) {
try {
//Save the modified object
contentService.save(content);
} catch (IllegalOrphanException ex) {
...
Meine content-service
...
@Transactional
public void save(Content content) throws IllegalOrphanException, NonexistentEntityException, RollbackFailureException, Exception {
try {
utx.begin();
em.merge(content);
utx.commit();
} catch (Exception ex) {
} finally {
if (em != null) {
em.close();
}
}
}
...
InformationsquelleAutor Webnet | 2012-04-05
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ihre Titel nicht korrekt ist. Sie haben erklärt, ein
Collection<State>
Ihre Eingabe ist einString
. Der Frühling konnte nicht wissen, wie man einenState
aus einerString
, man muss es sagen. Sehen Sie sich bitte die Frage: Umwandlung von String zu benutzerdefinierten Objekts für Spring MVC form der Daten verbindlich?InformationsquelleAutor Kai
Ich hatte das gleiche problem. ich bin mit Spring, Hibernate.
Ich habe eine Klasse mit zusammengesetzten Primärschlüssel, und übergeben Sie zwei Parameter in der Anfrage, mein Fehler war:
controller:
... Wenn die info ruft im controller die parameter
clave
ist, als wenn das ObjektTareaPK
des Primärschlüssels.ändere ich einfach den Namen des Parameters in meinem controller.
InformationsquelleAutor jmct_x