Je travail sur un projet avec spring MVC et angularjs, les operation CRUD fonction tres bien , mais lorsque j'aurai un form avec une liste select qui affiche les liste des objet d'une autre class qui une relation manyto-one, j'obtien cette error suivant :
org.springframework.beans.InvalidPropertyException: Invalid property 'siteesTypeSite[idTypeSite]' of bean class [model.Sites]:
Property referenced in indexed property path 'siteesTypeSite[idTypeSite]' is neither an array nor a List nor a Map; returned value was [2]
Is there something wrong with my mapping?
Sites.java mapping
public class Sites implements java.io.Serializable {
private int id;
@ManyToOne
@JoinColumn(name = "idTypeSite")
private TypeSites siteesTypeSite;
}
TypeSites.java mapping :
public class TypeSites implements java.io.Serializable {
private int idTypeSite;
private String typeSite;
@OneToMany(mappedBy = "siteesTypeSite",fetch = FetchType.LAZY)
private Set<Sites> sitees= new HashSet<Sites>(0);
}
controller class :
@Controller
@RequestMapping(value = "/protected/sites")
public class SitesController {
------
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<?> create(@ModelAttribute("site") Sites site,
@RequestParam(required = false) String searchFor,
@RequestParam(required = false,
defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
Locale locale) {
siteService.save(site);
}
Angularjs code :
$scope.createObject = function (newObjectForm) {
if (!newObjectForm.$valid) {
$scope.displayValidationError = true;
return;
}
$scope.lastAction = 'create';
var url = $scope.url;
var config = {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}};
$scope.addSearchParametersIfNeeded(config, false);
$scope.startDialogAjaxRequest();
$scope.sites.siteesTypeSite =JSON.parse($scope.sites.siteesTypeSite);
$http.post(url, $.param($scope.sites), config)
.success(function (data) {
$scope.finishAjaxCallOnSuccess(data, "#addObjectsModal", false);
})
.error(function(data, status, headers, config) {
$scope.handleErrorInDialogs(status);
});
};
JSP :
<select required
ng-model="sites.siteesTypeSite"
name="siteesTypeSite"
ng-change="getSelectedValue(sites.siteesTypeSite)"
value="{{sites.siteesTypeSite}}"
>
<option ng-repeat="typesites in page.source" value="{{typesites}}" >{{typesites.typeSite}}</option>
</select>
description here][2]
[1]: http://i.stack.imgur.com/WD8GO.png
[2]: http://i.stack.imgur.com/TsuyH.png
Partager