Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fixed language param of code macro

...

A Zone can be updated via an EventLink, ActionLink or Select component, or by a Form. All of these components support a zone parameter, which provides the id of the Zone's <div>. Clicking such a link will invoke an event handler method on the server as normal ... except that the return value of the event handler method is used to send a partial page response to the client, and the content of that response is used to update the Zone's <div> in place.

Code Block
xml
languagexml

<t:actionlink t:id="someLink" zone="myzone">update</t:actionlink>
...
<t:zone t:id="myZone" id="myzone">
    The current time is ${currentTime}
</t:zone>

...

This return value is often just the zone's own body (as below), but it can also be an injected component or block. The value will be rendered, and that markup will be used on the client side to update the Zone's <div>.

Code Block
java
languagejava

@Inject
private Request request;

@InjectComponent
private Zone myZone;
...
Object onClickFromSomeLink()
{
   return myZone.getBody(); // AJAX request, return zone's own body
} 

...

To support graceful degradation, you should detect that case in your event handler method and return a traditional response: a page, page name or page class. This is accomplished by injecting the Request object, and invoking the isXHR() method. This value will be true for Ajax requests, and false for traditional request.

Code Block
java
languagejava

@Inject
private Request request;

@InjectComponent
private Zone myZone;
...
Object onClickFromSomeLink()
{
    // return either the zone body (ajax) or whole page (non-ajax)
    return request.isXHR() ? myZone.getBody() : null;
} 

...

The renderer for each zone can be the zone itself, a block, a component, a Renderable or a RenderCommand ... or an object, such as String, that can be coerced to either of these.

Section
Column
Code Block
languagejava
titleFor Tapestry 5.3 and laterjava

@InjectComponent
private Zone userInput;

@InjectComponent
private Zone helpPanel;

@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

void onActionFromRegister()
{
    ajaxResponseRenderer.addRender("userInput",
        userInput).addRender("helpPanel", helpPanel);
}
Column
Code Block
languagejava
titleFor Tapestry 5.1, 5.2 and 5.3java

@Inject
private Form registrationForm;

@Inject Block registrationHelp;

Object onActionFromRegister()
{
    return new MultiZoneUpdate("userInput",
        registrationForm).add("helpPanel",
        registrationHelp);
}

    Note that MultiZoneUpdate is deprecated starting with Tapestry 5.3.

...

Remember that the component id (t:id) is used to inject the Zone component into the containing page or component. The
client-side id (id) is used ... on the client side to orchestrate requests and updates. You will often seen the following construct:

Code Block
xml
languagexml

<t:zone t:id="myZone" id="myzone"> ... </t:zone>

<t:actionlink t:id="update" zone="myzone">update</t:actionlink>

...

To have Tapestry update a zone without the usual yellow highlight effect, just specify "show" for the update parameter:

Code Block
languagexml
<t:zone t:id="myZone" t:update="show">

You may also define and use your own JavaScript effect function (with lower-case names), like this:

Code Block
JavaScript
languageJavaScriptjs

Tapestry.ElementEffect.myeffectname = function(element){ YourJavascriptCodeGoesHere; };

...

Autocomplete can be added to an existing text field:

Code Block
java
languagejava

  <t:textfield t:id="accountName" t:mixins="autocomplete" size="100"/>

...

You must write an event handler to provide these completions. The name of the event is "providecompletions". The context is the partial input value, and the return value will be converted into the selections for the user.

For example:

Code Block
java
languagejava

  List<String> onProvideCompletionsFromAccountName(String partial)
  {
    List<Account> matches = accountDAO.findByPartialAccountName(partial);

    List<String> result = new ArrayList<String>();

    for (Account a : matches)
    {
      result.add(a.getName());
    }

    return result;
  }

...