Component that triggers an action on the server with a subsequent full page refresh.
| Name | Type | Flags | Default | Default Prefix | Description |
|---|---|---|---|---|---|
| anchor | String | literal | An anchor value to append to the generated URL (the hash separator will be added automatically). | ||
| context | java.util.List | prop | The context for the link (optional parameter). This list of values will be converted into strings and included in the URI. The strings will be coerced back to whatever their values are and made available to event handler methods. | ||
| disabled | boolean | false | prop | If true, then then no link element is rendered (and no informal parameters as well). The body is, however, still rendered. | |
| zone | String | literal | Binding the zone parameter turns the link into a an Ajax control that causes the related zone to be updated. |
public class Account
{
private long _id;
private String _userName;
// etc., etc., ...
// Getters and setters omitted ...
}
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<body>
<h1>View Account #${account.id}</h1>
<t:beandisplay object="account"/>
<p>
[<t:actionlink t:id="delete" context="account.id">delete</t:actionlink>
</p>
</body>
</html>
public class ViewAccount
{
@Persist
private Account _account;
@InjectPage
private AccountsSummary _accountsSummaryPage;
@Inject
private AccountDAO _accountDAO;
public Account getAccount() { return _account; }
Object onActionFromDelete(long accountId)
{
_accountDAO.delete(accountId);
_accountsSummaryPage.setMessage(String.format("Account #%d has been deleted.", accountId));
return _accountsSummaryPage;
}
}
Notice how the context (from when the link was rendered) now becomes parameters to the event handler method.
The AccountDAO (data access object) service is responsible for the work, we then set a message on another page (the field for this message should be persistent) and return the page. Tapestry will send a redirect request to the client to display the page.
Rarely, you might need to pass more information in the context. For example, perhaps account id is not enought to uniquely identify the Account object in question - hypothetically, you may need to include a company id as well as the account id. You can build an object array to contain both values:
public Object[] getAccountContext()
{
return new Object[] { account.companyId, account.id };
}
Object onActionFromDelete(long companyId, long accountId)
{
_accountDAO.delete(companyId, accountId);
_accountsSummaryPage.setMessage(String.format("Account #%d has been deleted.", accountId));
return _accountsSummaryPage;
}In the template, this would be referenced as:
<p>
[<t:actionlink t:id="delete" context="accountContext">delete</t:actionlink>
</p>This highlights the use of the component class: any complicated processing should be offloaded out of the template and into the class.