java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

Daxing
I am getting the following validation error when I try to submit my form. The dropdown box populated with values from Sites.java gives this error:

    org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'model.TypeSites'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [model.TypeSites]: no matching editors or conversion strategy found
    at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:58)

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();
            $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()"
            value="{{sites.siteesTypeSite}}"
            >
    <option ng-repeat="typesites in page.source" value="{{typesites.idTypeSite}}" >{{typesites.typeSite}}</option>
    </select>

![enter image description here][1]


  [1]: http://i.stack.imgur.com/keIid.png
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

Zemi
Administrator
Hello Daxing,

welcome to the Thymeleaf Template Engine forums.

We are happy to help with any question related to Thymeleaf.

Regards,
   Zemi

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

Daxing
Thank you,
So i can't found the help for this  here?
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

Zemi
Administrator
Are you using Thymeleaf?

It seems a Java + JSP + AngularJS app.

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type

Daxing
For my webapp ,i'm using Angular ,Spring MVC, Data and Security