Your SlideShare is downloading. ×
Play framework
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Play framework

1,620
views

Published on

Published in: Design, Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,620
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
51
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Play! framework Agile web development. Created by Guillaume Bort 2007Sẩm Bảo Chung Web development with Play!
  • 2. Agenda Overview Main Concept  Five cool things you can do with play  Fix the bug and hit Reload  Simple stateless MVC architecture  Efficient template engine  Test driven development  Job Play enviroment DiscussSẩm Bảo Chung Web development with Play!
  • 3. Play Overview Pure Java More productive Java environment! Targets Restful architectures No compile, deploy, restart cycle - Fix the bug and hit reload! Clean template system - using Groovy, Scala template Exact errors (including line numbers, even for templates) Lots of built-in features for fast development Starts fast, runs fast Extensible by modulesSẩm Bảo Chung Web development with Play
  • 4. Main Concept Simple stateless MVC architecture Five cool things you can do with play Fix the bug and hit Reload Efficient template engine JPA Test driven development JobSẩm Bảo Chung Web development with Play!
  • 5. Play architecture MVC The Play framework is fully stateless and only request/response-oriented 4.AnHTTP Request is received by the framework. 6.TheRouter component tries to find the most specific route able to accept this request. 8.The corresponding action method is then invoked. 10.The application code is executed. 11.If a complex view needs to be generated, a template file is rendered. 13.The result of the action method (HTTP Response code, Content) is then written as an HTTP Response.Sẩm Bảo Chung Web development with Play!
  • 6. Routes file A routes file help play controller routine the request GET / Ap p l i c a t i o n . i n d e x GET / u s e r /{ username } Ap p l i c a t i o n . showUser POST / u s e r Ap p l i c a t i o n . c r e a t eUs e r DELETE / u s e r /{ username } Ap p l i c a t i o n . d e l e t eUs e r GET / p u b l i c staticDir:publicSẩm Bảo Chung Web development with Play
  • 7. Model A simple user @Entity public class User extends Model{ @Id public long id; @Required @Column(unique = true) public String username; @Required @Email public String email; }Sẩm Bảo Chung Web development with Play
  • 8. Controller UserController public class Application extends Controller { public static void index() { List<User> users = User.findAll(); render(users); } public static void showUser(String username) { User user = User.find("byUsername", username).first(); notFoundIfNull(user); render(user); }Sẩm Bảo Chung Web development with Play
  • 9. View List users (app/views/Application/index.html) #{ extends ’main .html ’ /} #{ set title :’Index ’ /} <ul > #{ list items :users , as:’user ’} <li > #{a @Application . showUser ( user . username )} ${ user . username } #{/ a} with email address ${ user . email } </li > #{/ list } </ul >Sẩm Bảo Chung Web development with Play
  • 10. Five cool things of Play! Bind an HTTP parameter to a Java method parameter Redirect to an action by calling the corresponding Java method render(…) , renderText(…), renderXML(…), renderJSON(…), renderBinary(…), redirect(…)Sẩm Bảo Chung Web development with Play
  • 11. Five cool things of Play! Don’t Repeat Yourself when passing Java objects to templates Play will automatically start the JPA Entity Manager using Hibernate and magically synchronize it when code is reloaded.Sẩm Bảo Chung Web development with Play
  • 12. Five cool things of Play! Straightforward file upload management #{form @uploadPhoto(), enctype:multipart/form- data} <input type="text" name="title" /> <input type="file" id="photo" name="photo" /> <input type="submit" value="Send it..." /> #{/} public static void uploadPhoto(String title, File photo) { ... }Sẩm Bảo Chung Web development with Play
  • 13. Fix the bug and hit Reload Whenever an error occurs, the framework makes its best effort to identify and show you the problemSẩm Bảo Chung Web development with Play
  • 14. Job  Doing the right thing at the right time • Scheduled jobs (housekeeping) • Bootstrap jobs (initial data providing) • Suspendable requests (rendering a PDF report without blocking the • connection thread pool) /* @Every("1h") */ @OnApplicationStart public class LoadDataJob extends Job { public void doJob() { /* .. do whatever you want */ } }Sẩm Bảo Chung Web development with Play
  • 15. Test driven development The integrated test runner makes it easy for you do test- driven development.Sẩm Bảo Chung Web development with Play
  • 16. Getting start Using the play command When the framework is correctly installed, open a shell and execute play. $ play You should see the play default message.Sẩm Bảo Chung Web development with Play
  • 17. Getting start Use the new command to create a new application. # play new myAppSẩm Bảo Chung Web development with Play
  • 18. Getting start You can start with command # play run myAppSẩm Bảo Chung Web development with Play
  • 19. Modules Some module on http://www.playframework.org/modules With: Scala Google App Engine PDF Generation SASS and SCSS Google Web Toolkit MongoDB Simple search Objectify To install locally these modules use the install command: play install gae-{version} To add this module as dependency of your application, add it to the dependencies.yml file: require: - play -> gae {version}.Sẩm Bảo Chung Web development with Play

×