Skip to content

VARIABLE JAVASCRIPT RESOLVER EXPRESSION (on external .js file) #331

@SylvainAssemat

Description

@SylvainAssemat

Hello

I just try to have a simple mechanism using javascript and read "variable" from controller java model (springboot)
When i use th:insert, it works. All the content of the .js files is well available in the HTML file
But
When i try via th:src, the behaviour is not the same,displaying "null"

Inside the common.js, i can log the variable.

let activeProfile = /*[[ ${activeProfile} ]]*/ null;
console.debug('ACTIVE PROFILE     : ', activeProfile);
    <script th:inline="javascript"            th:src="@{/js/common.js}"></script>


    <!-- <script th:inline="javascript">
        /*<![CDATA[*/
        /*[+ [# th:insert="~{../static/js/common.js}"       /] +]*/
        /*]]>*/
    </script> -->

I try to have the same behaviour but seems not possible ?

I think that when i use one or more th:insert process, i am on the same thread, so the model atttibute is "global" to all the .js file i insert.
When i use th:src i will be on a isolated thread for each .js requested... so individual model.addAttribute("","") has to be done ...
That's why it seems not working unfortunately

Have a nice end of day

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions