Learn Java for Web Development

(Tina Meador) #1
CHAPTER 8: Play with Java and Scala 377

Listing 8-11. Simple Template


@(books: List[Book])



    @for(book <- books) {
  • @book.getTitle()

  • }

You can then call this from any Java code like you would normally call a method on a class.


Content html = views.html.Application.index.render(books);


Listing 8-12 illustrates the code for the index.scala.html template that you will find in the
app/views folder.


Listing 8-12. index.scala.html



  1. @(books: List[Book], bookForm: Form[Book])



  2. @import helper._



  3. @main("books") {




  4. @books.size() book(s)








    • @for(book <- books) {




    • @book.label



    • @form(routes.Application.deleteBook(book.id)) {




    • }




    • }







  5. Add a new book





  6. @form(routes.Application.newBook()) {



  7. @inputText(bookForm("label"))








  8. }



  9. }

Free download pdf