Class Delegate

  extended by org.apache.tapestry5.corelib.components.Delegate

public class Delegate
extends Object

A component that does not do any rendering of its own, but will delegate to some other object that can do rendering. This other object may be a component or a Block (among other things).

This component may also be used to create inline components. For each informal parameter the value will be stored as a render variable. To create an inline component, create a block and use Delegate multiple times in the template to render the block passing parameters to Delegate. In the block body reference the render variables using the "var:" binding prefix and the name of the parameter.

Note that the default binding prefix for informal parameter values is "literal".

Component Parameters
NameDescriptionTypeFlagsDefaultDefault PrefixSince
toThe object which will be rendered in place of the Delegate component. This is typically a specific component instance, or a org.apache.tapestry5.Block.ObjectRequiredprop

The Delegate component allows us to be very flexible in how and what gets rendered, and in what order. In some cases, the object to be rendered may come from an entirely different page.

This example is simpler, and could easily be accomplished using an If component. We'll create a page that can be used for viewing or editting an object.


<html xmlns:t="">
        <h1>View Account</h1>

        <t:delegate to="activeBlock"/>

        <t:block id="view">
            <t:beandisplay object="account"/>

            <p><t:actionlink t:id="edit">Edit this account</t:actionlink></p>

        <t:block id="edit">
            <t:beaneditform t:id="account"/>

So we end up with a display of the Account's properties, and a link to activate edit mode. In edit mode, we use the other block and show a BeanEditForm.

public class ViewAccount
    private Account account;

    private boolean editMode;

    private Block edit, view;

    private AccountDAO accountDAO;

    public Account getAccount()
        return account;

    public void setAccount(Account account)
        account = account;
        editMode = false;

    void onSuccess()

        editMode = false;

    void onActionFromEdit()
        editMode = true;

    public Object getActiveBlock()
        return editMode ? edit : view;

The use of the @Inject annotation on a field of type Block is used to access a <t:block> element from the template. The field name, stripped of leading underscores, is matched against the block's id.

The rest is concerned with handling the form submission, turning on edit mode, and determining which block will be the one to render.

Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public Delegate()

Copyright © 2003-2012 The Apache Software Foundation.