Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Intellij Not Recognizing Model Variables in HTML. How to resolve model variables. I don't get any idea for this issue.

Intellij Not Recognizing Model Variables in HTML. How to resolve model variables. I don't get any idea for this issue.

2 Answers

I hope you are talking about this:

  1. You use Intellijidea Ultimate that has thymeleaf support
  2. you want for intellijidea to help you suggest variables that were passed to model, i.e.

Here is your Controller

@Controller 
public void someController {
  @RequestMapping("/")
  public String someMethod() {
    model.addAttribute("message", "message");
    return "index";
  }

And here is your "index.html", where when you type "m" you want to see suggestion window with your variable message, right?:

<p th:text="${message}"> </p>

Now if you put this in your "index.html"

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

Then in your th:text="${message}" you should see red squiggly lines saying that "Cannot resolve "message" variable..."

If that is your problem, then I think for now there is no solutions. Check this issue:

https://youtrack.jetbrains.com/issue/IDEA-132738#u=1437590406765

Although there was time when it worked:

https://blog.jetbrains.com/idea/2014/09/intellij-idea-14-ships-advanced-coding-assistance-for-thymeleaf/

Back then variables were set using "Context". Right now Spring is different, and well you can read about in in issue tracker above.

Hope It was what you've asked.

One last note: although variables added to model in @Controller will not be resolved, all Thymeleaf functions that starts with "#" will be available for you. That is helpful anyway.

And last but not the least, here is duplicate of your question:

https://teamtreehouse.com/community/spring-basics-intellij-not-recognizing-model-variables-in-html

Than you Alexander for your in-depth answer. I read about that on that links before you send me an answer but I was wonder maybe someone found the correct reply. Thank you anyway. Cheers