diff --git a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java index b1869aa707..751dbc4e9d 100644 --- a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java +++ b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java @@ -1,5 +1,6 @@ package com.baeldung.thymeleaf.controller; +import com.baeldung.thymeleaf.utils.StudentUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @@ -10,7 +11,8 @@ public class FunctionCallController { @RequestMapping(value = "/function-call", method = RequestMethod.GET) public String getExampleHTML(Model model) { - model.addAttribute("num", 2); + model.addAttribute("totalStudents", StudentUtils.buildStudents().size()); + model.addAttribute("student", StudentUtils.buildStudents().get(0)); return "functionCall.html"; } } diff --git a/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/functionCall.js b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/functionCall.js new file mode 100644 index 0000000000..41a71a73d2 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/functionCall.js @@ -0,0 +1,8 @@ + +function greetWorld() { + alert("hello world") +} + +function salute(name) { + alert("hello: " + name) +} \ No newline at end of file diff --git a/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html index 38555c3d2b..b3172a0c98 100644 --- a/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html +++ b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html @@ -4,25 +4,23 @@ Thymeleaf: Javascript function call +
Thymeleaf: Javascript function call
-
-
-
Inline function call
-
-
Without a variable
- -
-
-
With a variable
- -
+
+ + + + + + +
- - \ No newline at end of file