Play framework is joining the Typesafe Stack — More information in the official announcement
Meet the community
You can submit your code snippets here, to share patterns with the community. The content is uncensored, unfiltered and represents the views of the individual community members, not official Play usage. To contribute just login with your OpenID.
Spell checking a text may seem complicated. But for each complicated problem there exists a Web service API. Integrating it using Scala and Play is trivial.
Show the codeHow to create a Secure interceptor. The same principle is applied in the secure module.
Show the codeThis shows two simple classes linked bidirectionally by many to one and one to many relationship and a yaml file which loads sample data for each in.
Show the codeSimply shows how store uploaded images and display them later.
Show the codeEver wanted to keep track of record creation and update timestamps ?
The solution presented is an easy way around the use of DB triggers. It’s datavase agnostic and completely transparent to the developer: The JPA layer takes care of everything using @post hooks.
Show the codeUsing the new custom Binder of Play 1.1, you can automatically transform the request body into a Gson element.
Then you can extract the data ‘manually’ or use the Gson binding capabilities to transform it automatically into your domain object type.
The code snippet show a JsonObject binder, but you can of course do the same for other types like JsonArray.
Show the codeDownload and Install Play! 1.1.1, Clone and Run Sample Integration App with LinkedIn OAuth
Show the codeThis snippet shows how to authenticate with Twitter using Scribe. I’ve split the code up into three classes:
1. A Model to hold Twitter related stuff
2. A Controller
3. A Library class holding all the Twitter funcionality. It includes a couple of API methods you can try out
Tags for encoding and decoding URLs in the template engine.
Show the codeHow can I keep track of a job progress ?
Playframework does not provides a solution for tracking a Job progression, it’s the concern of the programmer.
So here a simple example done after reading the Play! GoogleGroup. It use the Cache (play.cache.Cache) and the UUID (play.libs.Codec).
Show the codeThis is a proposition for an alternative to the File Upload in Play! Framework (> 1.2). This aims to replace Blob for serving uploaded files through a Static Web Server.
Show the codeCentOS/Redhat init.d script to launch Play as a service.
Instalation:
copy file to /etc/init.d
chmod +x /etc/init.d/play
chkconfig --add /etc/init.d/play
chkconfig play on
Usage: (as root)
service play start
service play stop
service play status
I was working with a Postgres DB with multiple schemas and I needed to be able to switch from one schema to another on the fly. This little hack allows you to do that.
Show the codeHere simple code which allow you to generate jasper report from play framework.
Show the codeTemplate .gitignore file for playframework applications.
credits to https://github.com/github/gitignore/blob/master/PlayFramework.gitignore
Show the codeA simple file upload and renderBinary example using Play! 1.2.3 and GAE (google appengine) 1.5.6. Couldn’t find a complete (working) example of html file upload and renderBinary using Play! framework on GAE and then spent some time to get it working. Here it is
Show the codeThis is a upstart script for Play 1.x apps.
it features:
- boots on server boot
- automatically respawning of the app if it goes down
- runs the app as unprivileged user
- sets the working directory to the apps root directory ( so a simple new File(“public/images/myImage.png”) would work)
- specifying the profile id for the app to be run
have fun!
p.s.: if you have improvements, please fork the gist and drop me a line at
${me.firstname}@${me.firstname}${me.lastname}.com
Member(me):
firstname: dominik
lastname: dorn
Simply gzips your applications' responses.
Show the codeA (very basic) annotation and check. It expects that your model extends play.db.jpa.Model and also have the following limitations:
Just annotate the attribute like that:
@Unique
public String email;
I also recomend that you put a @Column annotation that creates a constraint at database:
@Unique
@Column ( unique = true )
public String email;
The @Unique annotation also permits empty/null values, so, you should probably use @Required annotation as well:
@Unique @Required @Column( unique = true )
public String email;
Fell free to fork the gist and customize the code for you necessities.
Show the codeBy default, when db=fs is specified play stores the h2 database file at db/h2/play with this setting you can specify another location for the h2 file database.
More info at h2 documentation site
Show the codeThis is very basic pagination functionality, completely agnostic of the underlying data.
Code + Example Usage:
https://gist.github.com/1379217
The code is based on this mailing list discussion:
http://groups.google.com/group/play-framework/browse_thread/thread/32f9e6f5ff6152a6?pli=1
A gist to add Facebook login to your application
Show the codePlay! Framework 1.2.x Pagination (this is a variation and modification of the version found on https://gist.github.com/1379217). This gist includes all the code you need to setup paging in your views minus the CSS to style the paging links.
Show the codeDemonstrates how to easily and fluently build routes from within Controller methods.
Check out the usage below.
Show the codePlay command for pushing SNAPSHOT releases into Nexus.
Currently this is just what we need but it would be really easy to include ‘releases’ support.
Usage.
play nexus-commit [-a]
-a: push the file without asking for confirmation (always)
Show the code