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

 

Scrollbar

Symbols are named configuration settings for Tapestry IOC-based services. Tapestry provides mechanisms for easy access to symbols from within such services.

...

The value on the inside is the symbol name. By convention, the symbol name is segmented with periods (for example, "tapestry.production-mode").

Built-in Symbols

...

Using Symbols in your Services

...

Code Block
java
java
public class MyService implements MyServiceInterface
{
  public MyService(@Value("${tapestry.production-mode}") boolean productionMode, ...)
  {
    if (productionMode) {
      . . .

Here Tapestry has coerced the "tapestry.production-mode" symbol to a boolean to be injected.

...

It's easy to use a symbol in a component class:

Code Block
languagejava
  @Inject
  @Symbol(SymbolConstants.PRODUCTION_MODE)
  private boolean productionMode;
  . . .
  void setupRender() {
    if (productionMode) {
        . . .
    }
  }

You can even use them directly in a component template, using the "symbol" binding prefix:

Code Block
languagexml
<t:if test="!symbol:tapestry.production-mode">
  <p>WARNING: We're running in development mode (slower, and less secure)</p>
</t:if>

...

From the previous example:

Code Block
languagejava
titleAppModule.java (partial)
  public void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
  {
    configuration.add("some-service-id", "WackyCollaborator");
  }

...

It is possible and valid to define one symbol in terms of one or more other symbols.

Code Block
languagejava
titleAppModule.java (partial)
  public void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
  {
      configuration.add("report.url", "http://${report.host}:${report.port}/${report.path}");
      configuration.add("report.host", "www.myreportsite.com");
      configuration.add("report.port", "80");
      configuration.add("report.path", "/report.cgi");
  }

The ordinary default for report.url will be: http://www.myreportsite.com:80/report.cgi.

However, this can be changed by making an overriding contribution to the ApplicationDefaults service configuration.

...