Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed broken footnote

...

Code Block
controlstrue
linenumberstrue

  <a t:id="home" class="nav">Back to home</a>
Code Block
controlstrue
linenumberstrue

  @Component(parameters={ "page=index" })
  private PageLink home;

...

Code Block
controlstrue
linenumberstrue

  <t:form t:id="login"> .... </t:form>
Code Block
controlstrue
linenumberstrue

  @InjectComponent
  private Form login;

...

Code Block
controlstrue
linenumberstrue

  @InjectPage
  private ConfirmRegistration confirmRegistration;

  Object onSuccessFromRegistrationForm()
  {
    confirmRegistration.setStatus("Registration accepted");
    confirmRegistration.setValidationCode(userRegistrationData.getValidationCode());

    return confirmRegistration;
  }

...

Code Block
controlstrue
linenumberstrue

	@Inject
	private ComponentEventResultProcessor processor;

...

Code Block
controlstrue
linenumberstrue

	@InjectService("ComponentEventResultProcessor")
	private ComponentEventResultProcessor processor;

...

Code Block
controlstrue
linenumberstrue

    @Marker(
    { Primary.class, Traditional.class })
    public ComponentEventResultProcessor buildComponentEventResultProcessor(
            Map<Class, ComponentEventResultProcessor> configuration)
    {
        return constructComponentEventResultProcessor(configuration);
    }

...

Code Block
controlstrue
linenumberstrue

    @Inject
	@Traditional @Primary
	private ComponentEventResultProcessor processor;

...

@Environmental is different; it exposes a request-scoped, dynamically bound value

Wiki Markup
{footnote}. The term "Environmental" was chosen as the value "comes from the environment", whatever that means. A name more evocative of its function still has not occurred to the Tapestry team!{footnote}

.

:

  • "Request scoped"Request scoped: different threads (processing different requests) will see different values when reading the field.
  • "Dynamically bound": the value is explicitly placed into the Environment, and can be overridden at any time.

Environmentals are a form of loosely connected communication between an outer component (or even a service) and an inner component. Example: the Form component places a FormSupport object into the environment. Other components, such as TextField, use the FormSupport when rendering to perform functions such as allocate unique control names or register client-side validations. The TextField doesn't require that the Form component be the immediate container component, or even an ancestor: a Form on one page may, indirectly, communicate with a TextField on some entirely different page. Neither component directly links to the other, the FormSupport is the conduit that connects them.

The term "Environmental" was chosen as the value "comes from the environment".

But wait ... I see I used the @Inject annotation and it still worked. What gives?

...

Code Block
Java
titleTapestryModule.java (partial)
Java

    /**
     * Builds a proxy to the current {@link JavaScriptSupport} inside this thread's {@link Environment}.
     * 
     * @since 5.2.0
     */
    public JavaScriptSupport buildJavaScriptSupport()
    {
        return environmentalBuilder.build(JavaScriptSupport.class);
    }

...

Code Block
Java
titleTapestryModule.java (partial)
Java

    public Request buildRequest()
    {
        return shadowBuilder.build(requestGlobals, "request", Request.class);
    }

...

Also remember that @Inject on fields works for components and for service implementations or other objects that Tapestry instantiates, but not on arbitrary objects (that are created via Java's new keyword).

Wiki Markup
{scrollbar}

...

}