Search code examples
javascripthibernatespring-bootjpathymeleaf

Property or field 'location' cannot be found on object of type javascript


I having troubles to get the object in javascript expression Thymeleaf, How can I resolved?

I m trying to fill a select option with the Location by javascript expression but i dont know i can access the platform.location.locationId

    $(document).ready(function () {

      /*[# th:if="${platform != null}"]*/

            $("#platformId").val( "[(${platform.platformId})]" );
            $("#asset").val( "[(${platform.asset})]" );
            $("#ismpSerialNumber").val( "[(${platform.ismpSerialNumber})]" );
            $("#ismpKitName").val( "[(${platform.ismpKitName})]" );
            $("#businessUnit").val("[(${platform.businessUnit})]");
            $("#project").val("[(${platform.project})]");
            $("#name").val("[(${platform.name})]");
            $("#chasisSerial").val("[(${platform.chasisSerial})]");
            $("#model").val("[(${platform.model})]");
            $("#serialPlatform").val("[(${platform.serialPlatform})]");
            $("#chasisModel").val("[(${platform.chasisModel})]");
            $("#finalStatus").val("[(${platform.finalStatus})]");
            $("#assignedTo").val("[(${platform.assignedTo})]");
            $("#ismNumber").val("[(${platform.ismNumber})]");
            $("#ownedBy").val("[(${platform.ownedBy})]");
            $("#locationId").val("[[${platform.location.locationId}]]");


      /*[/]*/

    });

EL1008E: Property or field 'location' cannot be found on object of type 'com.LTR.entity.Platform' - maybe not public or not valid?


Solution

  • Ensure that your platform entity has an attribute "location" and the class have a getter for it with the shape getLocation(). The error you are getting means thymeleaf can't access this attribute when it's building the resulting html to send to the client.

    On a side note, yes, you are using javascript to set some values, but thymeleaf will compose what ends up as your .val parameter using Java classes.