Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 240 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spring boot + thymeleaf in IntelliJ: cannot resolve vars

#11
I had the same problem and fixed it (ultimate 2021.3.2).
Intellij has a hard time guessing the type of the attribute(s).

Keep **www** in the namespace xmlns:th="http://www.thymeleaf.org" otherwise Intellij won't parse thymeleaf tags

If you initialize one model in a controler,

- don't use a method's return, declare a variable

String titre=post.getTitle();
model.addAttribute("title",titre);

- don't add attributes through sub methods, keep it in the main block

@GetMapping("/book")
public String ver(Model model) {
...
model.addAttribute("title", title);
return "frontpage";
}

- and don't use complex operator like the ternary one

model.addAttribute("titles", titles.size() > 0 ? titles : null);

If you initialize 2 or 3 models in you controler,
don't push null values

model.addAttribute("employees", null);
Reply

#12
I was resolve like following
click **Alt + Enter**

Lets try it!!!

[![enter image description here][1]][1]


[1]:
Reply

#13
# Update

**TL;DR:** skip to accepted answer below:

[To see links please register here]


As mentioned in the comments by multiple people, this solution is not correct. The Thymeleaf documentation (see

[To see links please register here]

), have in all their examples a version with `www.` included:

```html
<html xmlns:th="http://www.thymeleaf.org">
```

See also the [Standard-Dialect.xml](

[To see links please register here]

) on Github, which declares `namespace-uri` as:

```xml
namespace-uri="http://www.thymeleaf.org"
```

# Original Answer

I had two different portions of code: the first was showing the error and the second was not doing it.
I observed that there is a difference in the **xmlns:th** attribute.

**First Page: Not working!**

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">


**Second Page: Working!**

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://thymeleaf.org">


I removed the **www.** and it works for me!
Reply

#14
# Prerequisites

* Thymeleaf plugin is installed
* The `html` element has an XML namespace declaration for `th` that is set to `http://www.thymeleaf.org` (with `www.`), for example:

```
<html xmlns:th="http://www.thymeleaf.org">
```

# IntelliJ version >= 2017.3

Detection should work automatically. However, some people complain that it still does not work for them), the issue [IDEA-132738][2] should be fixed (@FloatOverflow: "I confirm that in version 2017.3 build 25.Oct.2017 the problem has been solved"):

> Status 2017.3
>
> Support for Spring Boot autoconfigured MVC applications is complete, all bundled autoconfiguration view types are supported.
>
> Fix versions: 2017.3

If variables are not automatically detected you can still add the `@thymesVar` annotation as shown below.

# IntelliJ version < 2017.3

It is, as [Andrew wrote][1], a known error [IDEA-132738][2]. There is a workaround how to get rid of the error marks in the IDE. IntelliJ also supports the semi-automatic generation of the below mentioned code:

> You can use <kbd>Alt</kbd>+<kbd>Enter</kbd> shortcut to invoke intention "Declare external variable in comment annotation" in order to get rid of "unresolved model attribute" in your views.

Add the following code to your `html` file:

<!--/* Workaround for bug

[To see links please register here]

-->
<!--@thymesVar id="post" type="your.package.Post"-->
<!--@thymesVar id="title" type="String"-->
<!--@thymesVar id="content" type="String"-->
<!--*/-->

If you use extensions objects constructed automatically by ThymeLeaf, such as `#temporals` from `thymeleaf-extras-java8time` for conversion of `java.time` objects:

<span th:text="${#temporals.format(person.birthDate,'yyyy-MM-dd')}"></span>

and IntelliJ cannot resolve them, use similar code, and just add `#` in front of the object name:

<!--@thymesVar id="#temporals" type="org.thymeleaf.extras.java8time.expression.Temporals"-->


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#15
In spring boot + thymeleaf, after adding a custom bean, everything worked. Hope it helps someone!



Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through