|
Play Framework/Scala example source code file (Controller.java)
The Controller.java Play Framework example source code
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package play.mvc;
import play.i18n.Lang;
import play.mvc.Http.*;
/**
* Superclass for a Java-based controller.
*/
public abstract class Controller extends Results implements Status, HeaderNames {
/**
* Returns the current HTTP context.
*/
public static Context ctx() {
return Http.Context.current();
}
/**
* Returns the current HTTP request.
*/
public static Request request() {
return Http.Context.current().request();
}
/**
* Returns the current lang.
*/
public static Lang lang() {
return Http.Context.current().lang();
}
/**
* Change durably the lang for the current user
* @param code New lang code to use (e.g. "fr", "en-US", etc.)
* @return true if the requested lang was supported by the application, otherwise false.
*/
public static boolean changeLang(String code) {
return Http.Context.current().changeLang(code);
}
/**
* Change durably the lang for the current user
* @param lang New Lang object to use
* @return true if the requested lang was supported by the application, otherwise false.
*/
public static boolean changeLang(Lang lang) {
return Http.Context.current().changeLang(lang);
}
/**
* Clear the lang for the current user.
*/
public static void clearLang() {
Http.Context.current().clearLang();
}
/**
* Returns the current HTTP response.
*/
public static Response response() {
return Http.Context.current().response();
}
/**
* Returns the current HTTP session.
*/
public static Session session() {
return Http.Context.current().session();
}
/**
* Puts a new value into the current session.
*/
public static void session(String key, String value) {
session().put(key, value);
}
/**
* Returns a value from the session.
*/
public static String session(String key) {
return session().get(key);
}
/**
* Returns the current HTTP flash scope.
*/
public static Flash flash() {
return Http.Context.current().flash();
}
/**
* Puts a new value into the flash scope.
*/
public static void flash(String key, String value) {
flash().put(key, value);
}
/**
* Returns a value from the flash scope.
*/
public static String flash(String key) {
return flash().get(key);
}
}
Other Play Framework source code examplesHere is a short list of links related to this Play Framework Controller.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.