Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SylvainAssemat opened this issue Jan 2, 2025 · 0 comments
Open

Comments

@SylvainAssemat
Copy link

SylvainAssemat commented Jan 2, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant