0

I have the following code:

@RestController
public class RestTmp {

    @Autowired
    SchemasService schemasService;

    @RequestMapping(path = "/editSchema/{id}")
    public void editSchemaById(Model model, @PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        String schemaERD = schemasService.editUser(id);
        model.addAttribute("message", schemaERD);
        response.sendRedirect("/drawdiagram");
    }
}

Can anyone tell me how i can get value from that variable "message" now?
I need to handle that value in my "/drawdiagram" ---> (drawdiagram.html)

I tried with thymeleaf something like that:

<script th:inline="javascript">
    /*<![CDATA[*/

    var message = /*[[${message}]]*/ 'default';
    console.log(message);

    /*]]>*/
</script>

but i am getting null all the time ... Can someone help me? :(

2 Answers 2

1

It seems you are adding the "comment-statement" (/* and */) once too many times. Remove them in the inner part. And keep the square brackets.

<script th:inline="javascript">
    /*<![CDATA[*/

    var message = [[${message}]];   <--- Keep square brackets on this line.
    console.log(message);

    /*]]>*/
</script>

I used the same link user404 mentions in the comment-section in that persons answer and that is working for me.

Sign up to request clarification or add additional context in comments.

Comments

1

inside your script tag, try this:

 var message = '${message}';

5 Comments

Thanks man but this is not solution for me :( i.imgur.com/TbZWPNs.png I don't know why but this is just normal "string" for compiler.
I tried that also and i am getting null :( I mentioned that in my post.
check if your message variable really sets null in controller.
Variable "message" in controller is ok, i tried also put sample string like "whatever string" into that "message" and i am getting null also. i.sstatic.net/sBMw8.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.