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

Excerpt
hiddentrue

the various annotations and methods you can add to Tapestry page and component classes

Scrollbar

 

This is a summary of the more common annotations and methods you can add to Tapestry pages and component classes.

Div
stylefloat:right
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel in ("component-classes","component-templates","components") and space = currentSpace()

For an exhaustive list, see the annotations list

Wiki Markup
{float:right|background=#eee}
{contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=component-classes,component-templates,components}
{float}

There's a lot of documentation scattered about describing the various annotations and methods you can add to Tapestry page and component classes. This is not an exhaustive list, but rather it covers some of the the more common scenarios.

Field Injection Annotations

Main articles: Component Classes, 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.

...

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 Parameters.

@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 Persistent Page Data.

...

Marks the field as a Session State Object (SSO). SSOs store global data, and can be injected into any page or component. The SSOs are stored in the session, using a key based on the Java type. SSOs are usually created on demand, but the create attribute can turn this off. See Session Storage Component Cheat Sheet

@SessionAttribute

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 Session Storage.

...

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.

...

Allows JavaScript libraries and CSS stylesheet files to be includes included in the rendered page. Each such file is added to the page only once, in the order in which the page renders.

...

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.

...

Note

Generally, a renderable object is a Block or a component. The object is pushed onto the stack of rendering operations, temporarily replacing the current component as the object to be rendered.

...

A render phase method may also return false, in which case the flow continues to an alternate render phase, as per the chart in the Component RenderingCheat Sheet reference page.

The most common cases:

...

The SymbolProvider service has two interfaces : FactoryDefaults and ApplicationDefaults. Tapestry provides 2 annotations in order to define which implementation you want to override in your AppModule : 

  • @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");
    }

 

Scrollbar