Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Section
Column
Code Block
javajava
titleHelloWorld.java
java
package org.example.myapp.components;
public class HelloWorld
{
}
Column
xml
Code Block
xml
titleHelloWorld.tml
xml
<html>
    Bonjour from HelloWorld component.
</html>

...

And here's a component that does the same thing, but without needing a template:

Code Block
javajava
titleHelloWorld.java -- without a template
java
package org.example.myapp.components;

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeginRender;

public class HelloWorld
{
    @BeginRender
    void renderMessage(MarkupWriter writer)
    {
        writer.write("Bonjour from HelloWorld component.");
    }
}

...

Be aware that you will need to provide getter and setter methods to access your classes' instance variables. Tapestry does not do this automatically unless you provide the @Property annotation on the field.

Since
5.3.2
5.3.2
Since release 5.3.2, instance variables may be protected, or package private (that is, no access modifier). Under specific circumstances they may even be public (public fields must either be final, or have the @[Retain|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Retain.html] annotation).

Transient Instance Variables

...

Note
titleAbout initialization

Never initialize an instance field to a mutable object at the point of declaration. If this is done, the instance created from that initializer becomes the default value for that field and is reused inside the component on every request. This could cause state to inadvertently be shared between different sessions in an application.

Deprecated
since5.2
For Tapestry 5.1 and earlier, in the rare event that you have a variable that can keep its value between requests and you would like to defeat that reset logic, then you can add a @[Retain|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Retain.html] annotation to the field. You should take care that no client-specific data is stored into such a field, since on a later request the same page _instance_ may be used for a different user. Likewise, on a later request for the _same_ client, a _different_ page instance may be used.

Use persistent fields to hold client-specific information from one request to the next.

...