scalaplayframeworkjacksonws-client

Scale-play response jsondata to view List


enter image description here

I got json data using ws. And then we will want to display it in a list format in view. I do not know how to do it. Please help me!

*MyGoal:

enter image description here


Solution

  • I may have misunderstood your question, but sounds like you want a browser page to view the data? You will need to define a view to display it in, and then invoke this view with the Ok method. For example, in your controller, replacing Ok(Json.toJson(json)) with Ok(views.html.messages(Messages)) and creating the file messages.scala.html in the views package, which looks something like:

    @(messages:List[Message]) {
      <table class="table table-striped">
      @messages.map { message =>
        <tr>
          <td>@message.id</td>
          <td>@message.text</td>
          ...
        </tr>
      }
      </table>
    }
    

    Anything beginning with @ is a scala expression. Use a template functions to decorate or standardise your pages, see Playframework Template Use Cases