welcome.scala.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. @(message: String, style: String = "java")
  2. @defining(play.core.PlayVersion.current) { version =>
  3. <link rel="stylesheet" media="screen" href="/@@documentation/resources/style/main.css">
  4. <section id="top">
  5. <div class="wrapper">
  6. <h1><a href="https://playframework.com/documentation/@version/Home">@message</a></h1>
  7. </div>
  8. </section>
  9. <div id="content" class="wrapper doc">
  10. <article>
  11. <h1>Welcome to Play</h1>
  12. <p>
  13. Congratulations, you’ve just created a new Play application. This page will help you with the next few steps.
  14. </p>
  15. <blockquote>
  16. <p>
  17. You’re using Play @version
  18. </p>
  19. </blockquote>
  20. <h2>Why do you see this page?</h2>
  21. <p>
  22. The <code>conf/routes</code> file defines a route that tells Play to invoke the <code>HomeController.index</code> action
  23. whenever a browser requests the <code>/</code> URI using the GET method:
  24. </p>
  25. <pre><code># Home page
  26. GET / controllers.HomeController.index</code></pre>
  27. <p>
  28. Play has invoked the <code>controllers.HomeController.index</code> method:
  29. </p>
  30. <pre><code>public static Result index() {
  31. return ok(index.render("Your new application is ready."));
  32. }</code></pre>
  33. <p>
  34. An action method handles the incoming HTTP request, and returns the HTTP result to send back to the web client.
  35. Here we send a <code>200 OK</code> response, using a template to fill its content.
  36. </p>
  37. <p>
  38. The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a standard Java class.
  39. </p>
  40. <pre><code>@@(message: String)
  41. @@main("Welcome to Play") {
  42. @@play20.welcome(message, style = "Java")
  43. }</code></pre>
  44. <p>
  45. The first line of the template defines the function signature. Here it just takes a single <code>String</code> parameter.
  46. Then this template calls another function defined in <code>app/views/main.scala.html</code> which displays the HTML layout, and another
  47. function that displays this welcome message. You can freely add any HTML fragment mixed with Scala code in this file.
  48. </p>
  49. <blockquote>
  50. <p>
  51. <strong>Note</strong> that Scala is fully compatible with Java, so if you don’t know Scala don’t panic, a Scala statement is very similar to a Java one.
  52. </p>
  53. </blockquote>
  54. <p>You can read more about <a href="https://www.playframework.com/documentation/@version/ScalaTemplates">Twirl</a>, the template language used by Play, and how Play handles <a href="https://www.playframework.com/documentation/@version/JavaActions">actions</a>.</p>
  55. <h2>Async Controller</h2>
  56. Now that you've seen how Play renders a page, take a look at <code>AsyncController.java</code>, which shows how to do asynchronous programming when handling a request. The code is almost exactly the same as <code>HomeController.java</code>, but instead of returning <code>Result</code>, the action returns <code>CompletionStage&lt;Result&gt;</code> to Play. When the execution completes, Play can use a thread to render the result without blocking the thread in the mean time.
  57. <!--
  58. <p>
  59. <a href="routes.AsyncController.message">Click here for the AsyncController action!</a>
  60. </p>
  61. -->
  62. <p>
  63. You can read more about <a href="https://www.playframework.com/documentation/@version/JavaAsync">asynchronous actions</a> in the documentation.
  64. </p>
  65. <h2>Count Controller</h2>
  66. <p>
  67. Both the HomeController and AsyncController are very simple, and typically controllers present the results of the interaction of several services. As an example, see the <code>CountController</code>, which shows how to inject a component into a controller and use the component when handling requests. The count controller increments every time you click on it, so keep clicking to see the numbers go up.
  68. </p>
  69. <!--
  70. <p>
  71. <a href="routes.CountController.count">Click here for the CountController action!</a>
  72. </p>
  73. -->
  74. <p>
  75. You can read more about <a href="https://www.playframework.com/documentation/@version/JavaDependencyInjection">dependency injection</a> in the documentation.
  76. </p>
  77. <h2>Need more info on the console?</h2>
  78. <p>
  79. For more information on the various commands you can run on Play, i.e. running tests and packaging applications for production, see <a href="https://playframework.com/documentation/@version/PlayConsole">Using the Play console</a>.
  80. </p>
  81. <h2>Need to set up an IDE?</h2>
  82. <p>
  83. You can start hacking your application right now using any text editor. Any changes will be automatically reloaded at each page refresh,
  84. including modifications made to Scala source files.
  85. </p>
  86. <p>
  87. If you want to set-up your application in <strong>IntelliJ IDEA</strong> or any other Java IDE, check the
  88. <a href="https://www.playframework.com/documentation/@version/IDE">Setting up your preferred IDE</a> page.
  89. </p>
  90. <h2>Need more documentation?</h2>
  91. <p>
  92. Play documentation is available at <a href="https://www.playframework.com/documentation/@version">https://www.playframework.com/documentation</a>.
  93. </p>
  94. <p>
  95. Play comes with lots of example templates showcasing various bits of Play functionality at <a href="https://www.playframework.com/download#examples">https://www.playframework.com/download#examples</a>.
  96. </p>
  97. <h2>Need more help?</h2>
  98. <p>
  99. Play questions are asked and answered on Stackoverflow using the "playframework" tag: <a href="https://stackoverflow.com/questions/tagged/playframework">https://stackoverflow.com/questions/tagged/playframework</a>
  100. </p>
  101. <p>
  102. The <a href="http://groups.google.com/group/play-framework">Play Google Group</a> is where Play users come to seek help,
  103. announce projects, and discuss issues and new features. If you don’t have a Google account, you can still join the mailing
  104. list by sending an e-mail to
  105. <strong>play-framework+subscribe@@googlegroups.com</strong>.
  106. </p>
  107. <p>
  108. Gitter is a real time chat channel, like IRC. The <a href="https://gitter.im/playframework/playframework">playframework/playframework</a> channel is used by Play users to discuss the ins and outs of writing great Play applications.
  109. </p>
  110. </article>
  111. <aside>
  112. <h3>Browse</h3>
  113. <ul>
  114. <li><a href="https://playframework.com/documentation/@version">Documentation</a></li>
  115. <li><a href="https://playframework.com/documentation/@version/api/@style/index.html">Browse the @{style.capitalize} API</a></li>
  116. </ul>
  117. <h3>Start here</h3>
  118. <ul>
  119. <li><a href="https://playframework.com/documentation/@version/PlayConsole">Using the Play console</a></li>
  120. <li><a href="https://playframework.com/documentation/@version/IDE">Setting up your preferred IDE</a></li>
  121. <li><a href="https://playframework.com/download#examples">Example Projects</a>
  122. </ul>
  123. <h3>Help here</h3>
  124. <ul>
  125. <li><a href="https://stackoverflow.com/questions/tagged/playframework">Stack Overflow</a></li>
  126. <li><a href="http://groups.google.com/group/play-framework">Mailing List</a></li>
  127. <li><a href="https://gitter.im/playframework/playframework">Gitter Channel</a></li>
  128. </ul>
  129. </aside>
  130. </div>
  131. }