Search code examples
javascriptspring-mvcjspthymeleaf

Another Thymeleaf won't load script and script file (.js) question - (works fine in parent jsp page, but when moved to template, doesn't load)


So I made a page that utilizes some javascript and also loads a js file. However, I need to move that code to a template file. When I do so, that script tag and the file are not loaded. And I don't get any error messages during page load in the browser, the file does not exist in browser, and there are no build errors or log messages. Here are snippets of code.

The following works in my "addUser.jsp" file.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <script type="text/javascript" th:src="@{/resources/js/selectListSort.js}"></script>
</head>
<body>
...
<script th:inline="javascript">
   // several event listener loaders
</script>
</body>

But when I move it to my officeAccess.jsp file, it fails to load. In addUser.jsp, I make the call:

<div th:replace="administration/fragments/officeAccess :: officeAccess ( userForm = ${userForm} )"></div>

All the html in officeAccess is loaded as expected, just the javascript and file fail to load.


Solution

  • From everything I've researched, what I'm trying to do isn't possible.

    Since I'm loading the template, the new code is loaded in the body and belong outside the body. Or... they're ignored when loaded via the template engine. I'm not sure which.

    In any case, I'll just load the scripts in the parent page as needed for the templates (since this does work).