2

I am building a web app in Java using the Play! framework and Twirl template engine, using IntelliJ IDEA. In the template there are a number of implicit variables which are available(flash, session, requestHeader). I can successfully reference any of these variables and my app will compile and run as expected. However, as these variables have not been explicitly declared, IDEA shows an error(eg. Cannot resolve symbol flash) and does not provide any code assistance. While it is not a huge problem I would like to fix this if possible.

I have searched quite a bit for a solution, and the JetBrains blog has a post on how to do this for Velocity templates, if someone could help me do the same for Twirl templates I would be very thankful!

Jackson

JacksonWeekes
  • 202
  • 3
  • 11

1 Answers1

0

I have found a solution to this problem, which is to refer to the fully qualified name within the code, ie. to access the flash variable use

@play.mvc.Http.Context.Implicit.flash

This can also be imported at the top of a template, then you can simply refer to @flash in the code.

This should not be necessary- Play! is aware of these variables without explicitly importing them, this is simply for IDEA's sake. Strangely enough, I found that after creating a new project through IDEA it actually did provide the expected behaviour- I could simply use @flash without the import and IDEA would work as expected. However once I closed and reopened the project the same problem would occur.

At the moment this is the best solution I have found, although I have contacted IntelliJ support and if they offer a better solution I will update my answer accordingly.

JacksonWeekes
  • 202
  • 3
  • 11