Play Framework Scala Template

Siavosh

I've worked around with Play Framework for a while but I'm almost new to Scala Templates . For me as a C-familiar language developer sometimes it looks a bit strange

I was wondering if someone here could help me understand this code better I took it from http://www.playframework.com/documentation/2.2.x/JavaGuide3 (Zentask Example)

@(projects: List[Project], todoTasks: List[Task])

@main("Welcome to Play") {

    <header>
        <hgroup>
            <h1>Dashboard</h1>
            <h2>Tasks over all projects</h2>
        </hgroup>
    </header>

    <article  class="tasks">
        @todoTasks.groupBy(_.project).map {
            case (project, tasks) => {
                <div class="folder" data-folder-id="@project.id">
                    <header>
                        <h3>@project.name</h3>
                    </header>
                    <ul class="list">
                        @tasks.map { task =>
                            <li data-task-id="@task.id">
                                <h4>@task.title</h4>
                                @if(task.dueDate != null) {
                                    <time datetime="@task.dueDate">
                                        @task.dueDate.format("MMM dd yyyy")</time>
                                }

                                @if(task.assignedTo != null && task.assignedTo.email != null) {
                                    <span class="assignedTo">@task.assignedTo.email</span>
                                }
                            </li>
                        }
                    </ul>
                </div>
            }
        }
    </article>
}

This 3 lines are really confusing for me :

@todoTasks.groupBy(_.project).map {

case (project, tasks) => {

@tasks.map { task =>

I do appreciate if anyone can explain me in more details what exactly these 3 lines are doing?

Thanks guys

Alex

Okay, so there are several transformations going on here.

@todoTasks.groupBy(_.project) says that a todoTask has a field called project, and we should transform that list of todoTasks into a Map where the project is the key and the values are all todoTasks that match the key.

.map { case (project, tasks) => { says that we now have a Map where the key is project and the value is a list of tasks. And if we have those two items (project, tasks), then we should do something with each task, the something is to what follows the =>

tip, you don't need to have a deep knowledge of scala to be productive as a java play developer, just do your transformations of the data in your java controller.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get scala template in a variable in Play Framework

From Dev

play framework passing sub class to scala template

From Dev

using bootstrap with play framework scala template

From Dev

Play framework scala template with case statement on enumeration

From Dev

play framework passing sub class to scala template

From Dev

using bootstrap with play framework scala template

From Dev

Play framework 2.1.3 function that will render scala template with given parameters

From Dev

Add <script> to the <head> from scala template tags in Play Framework 2

From Dev

Scala - unbound wildcard exception (Play Framework 2.3 Template)

From Dev

Play Framework trouble importing scala template from different package

From Dev

Populate Javascript array using Scala List in Play framework template

From Dev

Play framework Twirl template comparing javascript element and scala variable

From Dev

Populate Javascript array using Scala List in Play framework template

From Dev

Play! Framework: Scala code inside play. scala.html template

From Dev

Play framework in Scala deployment

From Dev

Using scala template code blocks and values as argument to template call (Play Framework)

From Dev

Dealing with Options in Scala Play Template

From Dev

Play scala template syntax for a string

From Dev

Play scala template with google Multimap

From Dev

Scala Play framework 2.2 - How to get information about a users loginstatus in template

From Dev

Play framework dynamic template include

From Dev

Play framework dynamic template include

From Dev

Use of @Singleton in Scala play framework

From Dev

Depedency injection framework of Play and Scala?

From Dev

Firebase and Play Framework (Scala) is it possible?

From Dev

Scala Play Framework - Dynamic Forms

From Dev

Scala parameter to Java (Play Framework)

From Dev

Scala backticks in Play Framework Routes

From Dev

Nested requests with Scala and play Framework

Related Related

  1. 1

    Get scala template in a variable in Play Framework

  2. 2

    play framework passing sub class to scala template

  3. 3

    using bootstrap with play framework scala template

  4. 4

    Play framework scala template with case statement on enumeration

  5. 5

    play framework passing sub class to scala template

  6. 6

    using bootstrap with play framework scala template

  7. 7

    Play framework 2.1.3 function that will render scala template with given parameters

  8. 8

    Add <script> to the <head> from scala template tags in Play Framework 2

  9. 9

    Scala - unbound wildcard exception (Play Framework 2.3 Template)

  10. 10

    Play Framework trouble importing scala template from different package

  11. 11

    Populate Javascript array using Scala List in Play framework template

  12. 12

    Play framework Twirl template comparing javascript element and scala variable

  13. 13

    Populate Javascript array using Scala List in Play framework template

  14. 14

    Play! Framework: Scala code inside play. scala.html template

  15. 15

    Play framework in Scala deployment

  16. 16

    Using scala template code blocks and values as argument to template call (Play Framework)

  17. 17

    Dealing with Options in Scala Play Template

  18. 18

    Play scala template syntax for a string

  19. 19

    Play scala template with google Multimap

  20. 20

    Scala Play framework 2.2 - How to get information about a users loginstatus in template

  21. 21

    Play framework dynamic template include

  22. 22

    Play framework dynamic template include

  23. 23

    Use of @Singleton in Scala play framework

  24. 24

    Depedency injection framework of Play and Scala?

  25. 25

    Firebase and Play Framework (Scala) is it possible?

  26. 26

    Scala Play Framework - Dynamic Forms

  27. 27

    Scala parameter to Java (Play Framework)

  28. 28

    Scala backticks in Play Framework Routes

  29. 29

    Nested requests with Scala and play Framework

HotTag

Archive