![JAR search and dependency download from the Maven repository](/logo.png)
no.tornado.web.annotations.Page Maven / Gradle / Ivy
Show all versions of web Show documentation
package no.tornado.web.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Every {@link no.tornado.web.engine.Controller Controller} you create must be annoted with the {@literal @}Page annotation.
* The {@link no.tornado.web.processors.PageProcessor Page Annotation Processor} will automatically register routes for this
* page in the {@link no.tornado.web.engine.SiteConfig SiteConfig}, so that your controller can be accessed via the configured path.
*
* You can set a path for your page either by setting the annotation parameter {@link #path()} or by adding one or more language
* specific resources with the same name as the controller to have different paths for different langauges. In case you add language
* resources but do not add a path=
property in the resource bundle, the path from the annotation parameter {@link #path()}
* is used for the language in question.
*
* The same mechanism is used for the {@link #title()} parameter. You can override the title in the language specific resource file,
* or fallback to the default one specified in the annotation.
*
* Here is an example of adding a default path via annotation, and overriding it in the French resource bundle. See the
* {@link no.tornado.web.resources.Resource Resource class} for more information about how resource bundles are resolved.
*
* GreetController.java
*
*{@literal @}Page(path = "/hello")
* public class GreetController extends Controller {
*
* }
*
*
* GreetController_en.properties
*
* title=Hello world
*
*
* GreetController_fr.properties
*
* path=/allo
* title=Bonjour tout le monde
*
*
* All properties added to a controller resource bundle is directly available in the root context for any Freemarker
* content added to the template of the controller as well.
*
* You can override the contentType for the page by setting the the {@link #contentType()} annotation, or
* programatically by calling request.setContentType()
in your {@link no.tornado.web.engine.Controller Controller}.
*
* If you want to serve the page as a download to the user, you can set the {@link #filename()} parameter, or programmatically
* by adding the Content-Disposition
header as described in
* RFC2616 Section 19.
*
* For the content processing to work, you must enable annotation processing for your project. See the documentation of
* {@link no.tornado.web.annotations.ContentFolder ContentFolder} for information about configuring the annotation processors.
*
* @author edvin
* @version $Id: $Id
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Page {
String path() default "";
String title() default "";
String contentType() default "text/html";
String filename() default "";
}