Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed bad links due to copy-paste from cwiki-test

...

For an exhaustive list, see the annotations list.

Field Injection Annotations

Main articles: Component Cheat Sheet, Component Cheat Sheet, Component Cheat SheetClasses, Injection, Annotations

@Inject

...

Service Injection

In most cases, the injected value is a service; the service is located by type. If there are ambiguities, caused by multiple services implementing the same interface, you'll see injection exceptions. You can resolve those exceptions by adding marker annotations to select a specific service, or by adding @Service to specify the specific service ID you want.

...

Injects a page of the application. Normally, the page to inject is identified based on the field type. The value attribute can be specified, in which case the page to be injected is identified by name.

@Environmental

Injects an environmental object; such objects are request scoped but may be overridden at any time using the methods of the Environment service. Environmental objects are used to allow outer components to communicate with components they enclose.

...

Field Behavior Annotations

Main articles: Component Cheat Sheet, Component Cheat SheetClasses, Annotations

@PageActivationContext

This annotation is allowed on a single field; the value of the field will be included in URLs for the page as the page's activation context. This is an alternative to implementing event handler methods
for the activate and passivate events directly.

...

Marks the field as a component parameter. Attributes of the annotation allow the parameter to be marked as required or optional. If the parameter value will typically be a literal string (for example, the title parameter to a Layout component), you should add defaultPrefix=BindingConstants.LITERAL to the annotation so that users of the component won't have to use the "literal:" binding prefix with the parameter. See Component Cheat SheetParameters.

@Persist

Marks the field as a persistent value, one that maintains its value between requests. The default strategy is to simply store the value in the session (which is created as needed). Other strategies can be specified by name as the value attribute. See Component Cheat Sheet Persistent Page Data.

@Property

Directs Tapestry to automatically generate a getter and a setter for the field, converting it to a JavaBeans property than can be referenced from the template.

...

In Tapestry 5.2 and later, marks the field as a Session Attribute. Like Session State Objects (SSO), a Session Attribute is stored in the session, however Session Attributes are stored by using a name you choose rather than based on the Java type. See Component Cheat Sheet Session Storage.

@ActivationRequestParameter

...

Method Annotations

Main articles: Component Cheat Sheet, Component Cheat SheetClasses, Annotations

@OnEvent

Marks a method as an event handler method. Such methods may have any visibility, and typically use package private visibility (that is, no visibility keyword at all). By default, the method will handle the action event from any component; the value attribute controls the matched event, and the component annotation is used to limit the event source.

...

Note

The support for this annotation comes from the tapestry-hibernate module or tapestry-jpa module.

@Cached

Used on methods that perform expensive operations, such as database queries. The first time such a method is invoked, the return value is cached. Future invocations of the same method return the cached value.

...

Parameter Annotations

Main article: Component Cheat SheetParameters

@RequestParameter

Used with event handler methods to get the value for the parameter from a request query parameter.

...

The method ComponentResources.renderInformalParameters() can be used to include the informal parameters within the element rendered by your component.

@Secure

Main Article: Security

Marks the page as accessible only via secure (HTTPs). Any attempt to access the page via standard HTTP will be redirected to the HTTPs version.

...

Render Phase Methods

Main article: Component Cheat SheetRendering

Render phase methods are close cousins to event handler methods; they are how Tapestry integrates your code into the overall rendering of the page. For each render phase, there's an annotation and corresponding naming convention to define a render phase method:

...

Page Life Cycle Methods

Main article: Component Cheat Sheet Page Life Cycle

Pages have a life cycle and this is represented by a third set of annotations or method naming conventions. Life cycle methods may appear on a page or any component of a page.

...

  • @FactoryDefaults

    Code Block
    languagejava
    titleAppModule.java (partial) with @FactoryDefaults
    @Contribute(SymbolProvider.class)
    @FactoryDefaults
    public void setParam(MappedConfiguration< String, String> configuration){
      configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
    }
  • @ApplicationDefaults

    Code Block
    languagejava
    titleAppModule.java (partial) with @ApplicationDefaults
    @Contribute(SymbolProvider.class)
    @ApplicationDefaults
    public void setParam(MappedConfiguration< String, String> configuration){
      configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
    }

...