This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Default Parameter

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: restore





Avoiding repetition when using component parameters by adding autoconnect=true

Many of the components provided with Tapestry share a common behavior: if the component's id matches a property of the container, then some parameter of the component (usually value) defaults to that property.

titleRelated Articles
Content by Label
titleRelated Articles
cqllabel = "parameters" and space = currentSpace()

This is desirable, in terms of not having to specify the component's id and then specify the same value as some other parameter.

Let's say you have created a component, RichTextEditor, which operates like a normal TextArea component, but provides a JavaScript rich text editor. You might start with something like:

Code Block
public class RichTextEditor implements Field
  private String value;

  . . . // Lots more code not shown here

However, the weakness here is when you make use of the component. You template may look like:

Code Block
    <t:label for="profile"/>
    <t:richtexteditor t:id="profile" value="profile"/>

Every component has a unique id; if you don't assign one with the t:id attribute, Tapestry will assign a less meaningful one. Component ids can end up inside URLs or used as query parameter names, so using meaningful ids helps if you are ever stuck debugging a request.

This repetition can be avoided by adding the autoconnect attribute to the @Parameter annotation:

Code Block
  @Parameter(required=true, autoconnect=true)
  private String value;

This can now be written as <t:richtexteditor t:id="profile"/>. The unwanted repetition is gone: we set the id of the component and the property it edits in a single pass.