Here i use to concatenate 2 Lists (with same type) using this :+
and the code is testResult :+ studentsearch
the length of the list get value zero in the console
Controller
@RequestMapping(value = Array("parent/ViewReports.html"))
def viewReportPage(test: Test): String = {
var userAccount: UserAccount = secService.getLoggedUserAccount
var z = userAccount.getId().toLong
var studentsearch: java.util.List[StudentTest] = Nil
var studentTestResult: java.util.List[StudentTest] =Nil
var testResult: java.util.List[StudentTest] =Nil
var searchstudent = parentStudentService.findParentStudentByParent(z)
for(srchStd <- searchstudent){
var sid= srchStd.getStudent().getId()
studentsearch = studentTestService.findAllStudentTestByStudent(sid)
}
testResult :+ studentsearch
println("Length:" +testResult.length)
studentTestResult = ListBuffer(testResult: _*) .
results = studentTestResult
"redirect:/parent/result.html"
}
the concatenate code is wrong ?
please share your answers
Your code uses scala constructs in an interesting way. Which might not lead to correct results. The for comprehension in
reassigns
studentsearch
in each iteration to a new value, so in the end it is set to the value of the last iteration. If you want to accumulate the results something likewill result in all tests collected in
testResult
.The import of
scala.collection.JavaConversions._
helps converting between scala and java collections. More information can be found here: http://www.scala-lang.org/api/current/index.html#scala.collection.JavaConversions$.