Compilation error in scala template when passing arraylist: Not found value

I am trying to pass arraylist to a scala pattern from a playback controller.

In my controller

List<Profile> profiles = Profile.findAll(); return ok(contacts.render(profiles)); 

In the contacts.scala.html template

 @import models.com.contactmanager.Profile @(profiles: List[Profile]) 

I get an error message:

 not found: value profiles [error] 

for string

 @(profiles: List[Profile]) 
+4
source share
2 answers

In the Scala template parameter lists, you should use (a) the fully qualified class name or (b) import them into your Build.scala.

(a)

 @(profiles: List[models.com.contactmanager.Profile]) 

(b)

 //Play 2.2 val main = PlayProject(…).settings( templatesImport += "models.com.contactmanager.Profile" ) 

For Play 2.3 API has changed: https://www.playframework.com/documentation/2.3.x/ScalaTemplates#Import-statements

 TwirlKeys.templateImports += "models.com.contactmanager.Profile" 
+7
source

I assume that the import statement should be lower than the parameter operator.

Try to switch the order

 @import models.com.contactmanager.Profile @(profiles: List[Profile]) 

to

 @(profiles: List[Profile]) @import models.com.contactmanager.Profile 
+1
source

Source: https://habr.com/ru/post/1498456/


All Articles