Skip to content

Instantly share code, notes, and snippets.

@wbspry
Created August 6, 2014 09:52
Show Gist options
  • Save wbspry/8d5fb6c9e5aff03679c1 to your computer and use it in GitHub Desktop.
Save wbspry/8d5fb6c9e5aff03679c1 to your computer and use it in GitHub Desktop.
Playframework付属のサンプル'websocket-chat'を見てみる(1/4) ref: http://qiita.com/yyyske/items/d9e3cf69f7a6f5fb732b
public static Result chatRoom(String username) {
if(username == null || username.trim().equals("")) {
flash("error", "Please choose a valid username.");
return redirect(routes.Application.index());
}
return ok(chatRoom.render(username));
}
flash("error", "Please choose a valid username.");
GET /room controllers.Application.chatRoom(username: String ?= null)
@main(null) {
@if(flash.containsKey("error")) {
<div class="alert-message error">
<p>
<strong>Oops!</strong> @flash.get("error")
</p>
</div>
}
<div class="alert-message block-message info">
<p>
<strong>This is the Play Websocket sample application!</strong>
To start, choose a username and sign in using the top right form.
</p>
</div>
}
@if(connected != null) {
<p class="pull-right">
Logged in as @connected —
<a href="@routes.Application.index()">Disconnect</a>
</p>
} else {
<form action="@routes.Application.chatRoom()" class="pull-right">
<input id="username" name="username" class="input-small"
type="text" placeholder="Username">
<button class="btn" type="submit">Sign in</button>
</form>
}
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
GET /room controllers.Application.chatRoom(username: String ?= null)
GET /room/chat controllers.Application.chat(username)
GET /assets/javascripts/chatroom.js controllers.Application.chatRoomJs(username)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment