1 | # Suggested Play 2.0 alternatives for Play 1.x features |
---|
2 | |
---|
3 | <table> |
---|
4 | <tr> |
---|
5 | <th>Feature</th> |
---|
6 | <th>Play 1.x</th> |
---|
7 | <th>Play 2.0</th> |
---|
8 | </tr> |
---|
9 | <tr> |
---|
10 | <td colspan="3">Templates</td> |
---|
11 | </tr> |
---|
12 | <tr> |
---|
13 | <td>Iterate</td> |
---|
14 | <td>#{list items:collection, as:'var' } ...$var... #{/list}</td> |
---|
15 | <td>@for(var <- collection) { ... @var ... }</td> |
---|
16 | </tr> |
---|
17 | <tr> |
---|
18 | <td>Iteration index</td> |
---|
19 | <td>#{list items:collection, as:'var' } ...$var_index... #{/list}</td> |
---|
20 | <td>@for((var,index) <- collection.zipWithIndex) { ...@index @var ... }</td> |
---|
21 | </tr> |
---|
22 | <tr> |
---|
23 | <td>Relative URL</td> |
---|
24 | <td>@{controller.method}</td> |
---|
25 | <td>@routes.Controller.method()</td> |
---|
26 | </tr> |
---|
27 | <tr> |
---|
28 | <td>Absolute URL</td> |
---|
29 | <td>@@{controller.method}</td> |
---|
30 | <td> @routes.Controller.method().absoluteURL()</td> |
---|
31 | </tr> |
---|
32 | <tr> |
---|
33 | <td>Secure URL</td> |
---|
34 | <td>@{Admin.login().secure()}</td> |
---|
35 | <td>@routes.Admin.login() .absoluteURL(secure = true)</td> |
---|
36 | </tr> |
---|
37 | <tr> |
---|
38 | <td>Asset URL</td> |
---|
39 | <td>@{'/public/images/logo_16x16.png'}</td> |
---|
40 | <td>@routes.Assets.at("images/logo_16x16.png")</td> |
---|
41 | </tr> |
---|
42 | <tr> |
---|
43 | <td>Messages (i18n)</td> |
---|
44 | <td>&{'key.for.message'}</td> |
---|
45 | <td>@Messages("key.for.message")</td> |
---|
46 | </tr> |
---|
47 | <tr> |
---|
48 | <td colspan="3">Controller</td> |
---|
49 | </tr> |
---|
50 | <tr> |
---|
51 | <td>Configuration</td> |
---|
52 | <td>Play.configuration.getProperty("log.level");</td> |
---|
53 | <td>Play.application().configuration() .getString("log.level");</td> |
---|
54 | </tr> |
---|
55 | <tr> |
---|
56 | <td>Application Path</td> |
---|
57 | <td>play.Play.applicationPath;</td> |
---|
58 | <td>play.Play.application().path();</td> |
---|
59 | </tr> |
---|
60 | <tr> |
---|
61 | <td>Run level</td> |
---|
62 | <td>play.Play.configuration .get("application.mode").equals("DEV");</td> |
---|
63 | <td>Play.application().isDev()</td> |
---|
64 | </tr> |
---|
65 | <tr> |
---|
66 | <td>HTTP Parameters</td> |
---|
67 | <td>params.get("name");</td> |
---|
68 | <td>DynamicForm form = form().bindFromRequest(); |
---|
69 | form.get("name");</td> |
---|
70 | </tr> |
---|
71 | <tr> |
---|
72 | <td>Reverse Router</td> |
---|
73 | <td>Router.reverse("Users.activateUser") .add("activationKey",user.getActivationUUID());</td> |
---|
74 | <td>controllers.routes.Users .activateUser(user.getActivationUUID());</td> |
---|
75 | </tr> |
---|
76 | <tr> |
---|
77 | <td>Forward to View</td> |
---|
78 | <td>renderTemplate("Clients/showClient.html", id, client);</td> |
---|
79 | <td>ok(view.html.Clients .showClient( id, client ));</td> |
---|
80 | </tr> |
---|
81 | <tr> |
---|
82 | <td colspan="3">Outside the Controller scope</td> |
---|
83 | </tr> |
---|
84 | <tr> |
---|
85 | <td>Request</td> |
---|
86 | <td>play.mvc.Http.Request.current()</td> |
---|
87 | <td>Request request = play.mvc.Http.Context .current().request()</td> |
---|
88 | </tr> |
---|
89 | <tr> |
---|
90 | <td>Response</td> |
---|
91 | <td>play.mvc.Http.Response.current()</td> |
---|
92 | <td>Response response = play.mvc.Http.Context .current().response()</td> |
---|
93 | </tr> |
---|
94 | <tr> |
---|
95 | <td>Session</td> |
---|
96 | <td>play.mvc.Http.Session.current()</td> |
---|
97 | <td>Session session = play.mvc.Http.Context .current().session()</td> |
---|
98 | </tr> |
---|
99 | <tr> |
---|
100 | <td>Flash</td> |
---|
101 | <td>play.mvc.Http.Flash.current()</td> |
---|
102 | <td>Flash flash = play.mvc.Http.Context .current().flash()</td> |
---|
103 | </tr> |
---|
104 | <tr> |
---|
105 | <td colspan="3">Misc</td> |
---|
106 | <tr> |
---|
107 | <td>Job at start</td> |
---|
108 | <td>@OnApplicationStart</td> |
---|
109 | <td><a href="http://www.playframework.org/documentation/2.0/JavaGlobal">Global.onStart</td> |
---|
110 | </tr> |
---|
111 | </tr> |
---|
112 | </table> |
---|