I'm trying to create a webpage (using the play framework) which displays the user's name, date of birth etc. Where I am getting stuck is attempting to display a list of unknown size in an html page. I currently have:
@(currentUser : Profile)
@main("Profile") {
<div>
<h1><b>@currentUser.getFirstName() @currentUser.getLastName()</b></h1>
<p>@currentUser.getDateofBirth</p>
<b>Nationalities</b>
<ul><p id="natInput"></p></ul>
<script>
for (var i = 0; i < "@currentUser.getNationalities().size()"; i++) {
document.getElementById("natInput").innerHTML += "<li>" + "@currentUser.getNationalities().get(i)" + "</li>";
}
</script>
</div>
}
Profile is a basic java class which only contains getters and setters, and .getNationalities returns a List. @Main is another html file which stores the base design of the website, not really relevant to this.
As you can see, I'm trying to use the .get method to loop through the list of nationalities for the user, but unfortunately the "i" variable used in the get is not recognised, as it is a javascript variable in html. Every other part of this code appears to work as expected, and the .get works when the "i" is replaced with an integer, such as 0 or 1.
Any ideas how I could get each individual element of this list? Any help would be greatly appreciated