Abhishek Agarwal
Abhishek Agarwal

Reputation: 922

Spring + Thymeleaf not able to populate String on render

I have a testt.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.thymeleaf.org ">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Advanced Test</title>
</head>
<body>

<form action="#" th:action="@{getClasses}" method="GET">
<br />
<br />
<p style="margin-left: 35px">Submit fully classified package names</p>
        Class Name: <input type="text" name="class_name" size="90px"></input> 
        <input type="text" name="classes" size="90px" th:field="${foo}"></input>
        <input type="submit" value="Submit" ></input> <br />

</form>
</body>
</html>

And have the following code in the controller method:

model.addAttribute("foo", "foo");
                return "testt";

Why "foo" is not populating in the html? If instead of String i add an object and try to get its variable it works fine.

Upvotes: 0

Views: 144

Answers (2)

Wermerb
Wermerb

Reputation: 1049

i think if you want use it like this you should use th:value instead of th:field

Upvotes: 1

Jaiwo99
Jaiwo99

Reputation: 10017

You need this th:field=__${foo}__,

have a look at the doc here:http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html

Upvotes: 0

Related Questions