Cześć,
mam problem z dodaniem za pomocą formularza nowego obiektu SystemContract. Obiekt posiada klucz obcy do tabeli/obiektu system.
W formularzu wybór system realizowany jest przez tag SELECT.
Przy próbie dodania pojawia się poniższy błąd. Rozumiem, że spring nie jest wstanie utworzyć obiektu typu system. Ale nie do końca rozumiem co ma zrobić.
Treść Błędu.
2017-01-21 17:56:52.338 DEBUG 10168 --- [nio-8080-exec-2] org.springframework.beans.BeanUtils : No property editor [org.customer.ml.Entity.SystemEditor] found for type org.customer.ml.Entity.System according to 'Editor' suffix convention
2017-01-21 17:56:52.345 TRACE 10168 --- [nio-8080-exec-2] o.s.beans.TypeConverterDelegate : No String constructor found on type [org.customer.ml.Entity.System]
java.lang.NoSuchMethodException: org.customer.ml.Entity.System.<init>(java.lang.String)
at java.lang.Class.getConstructor0(Class.java:2892) ~[na:1.7.0_79]
at java.lang.Class.getConstructor(Class.java:1723) ~[na:1.7.0_79]
2017-01-21 17:56:52.417 TRACE 10168 --- [nio-8080-exec-2] .w.s.m.m.a.ServletInvocableHandlerMethod : Invoking 'org.customer.ml.Controller.SysContractController.submitContract' with arguments [org.customer.ml.Entity.SystemContract@777c73ff, org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'systemContract' on field 'system': rejected value [1]; codes [typeMismatch.systemContract.system,typeMismatch.system,typeMismatch.org.customer.ml.Entity.System,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [systemContract.system,system]; arguments []; default message [system]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.customer.ml.Entity.System' for property 'system'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.customer.ml.Entity.System' for property 'system': no matching editors or conversion strategy found]]
@Entity
@Table(name = "contracts")
public class SystemContract {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "system_id", referencedColumnName = "id")
private System system;
// itd.
Fragment formularza dodania kontraktu w JSP i wybór systemu :
<select class="form-control" name="system" id="system">
<c:forEach items="${systems}" var="system">
<option value="${system.id}">${system.name}</option>
</c:forEach>
</select>
Kontroler:
@RequestMapping(value="/", method = RequestMethod.POST)
public String submitContract(@Valid @ModelAttribute SystemContract sysContract, BindingResult results){
if (results.hasErrors())
return "index";
this.sysContractService.insert(sysContract);
return "index";
}