Created
February 1, 2012 10:40
-
-
Save masahitojp/1716424 to your computer and use it in GitHub Desktop.
Play2.0ではsession.getIDがないよ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import play.libs | |
import java.util.UUID; | |
import play.cache.Cache | |
object Application extends Controller { | |
def index = Action {implicit request => | |
val ID_KEY = "___ID" | |
var id ="" | |
if(request.session.data.contains(ID_KEY)){ | |
id = request.session.data(ID_KEY) | |
} | |
else{ | |
id = UUID.randomUUID().toString() | |
// request.session.dataはimmutableなので、ここで追加は無理。考えなおしが必要 | |
// request.session.data.updated(ID_KEY, id) | |
} | |
Cache.set(id + "-message", "test") | |
Ok(views.html.index(id)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment