Creates an <a>
hyperlink that notifies the component when the link is
triggered. The link includes some context-specific data that is made available to
the component's listener.
See the Developers Guide DirectLink listeners for a more complete description.
See also: ExternalLink , GenericLink , PageLink , ServiceLink
Name | Type | Required | Default | Description |
---|---|---|---|---|
listener | IActionListener | yes | Specifies an object that is notified when the link is clicked, which is typically a listener method of its container (for example, listeners. method ). | |
parameters |
Object or
Object[] or List |
no |
An array of objects to be encoded into the URL. These parameters will be decoded when the link is triggered. In a web application built onto of Enterprise JavaBeans, the context is often the primary key of some Entity bean; typically such keys are Strings or Integers.
A listener method can retrieve the parameters three ways:
Prior to release 2.2, the parameters were always type String. They may now be of any type; type will be maintained when the parameters are later retrieved by a listener. See SqueezAdaptor for more details. |
|
disabled | boolean | no | false | Controls whether the link is produced. If disabled, the portion of the template the link surrounds is still rendered, but not the link itself. |
stateful | boolean | no | true | If true (the default), then the component requires an active (i.e., non-new) HttpSession when triggered. Failing that, it throws a StaleLinkException . If false, then no check is necessary. The latter works well with links that encode all necessary state inside the URL itself. |
anchor | String | no | The name of an anchor or element to link to. The final URL will have '#' and the anchor appended to it. | |
scheme | String | no | The required scheme ("http" or "https", typically) for the URL. This will force the creation of an absolute URL when the current request's scheme does not match the value for this parameter. This is most often used to switch to "https" for secure portions of an application (such as a login page), before switching back to standard "http" for the majority of an application. | |
port | Integer | no | The required port (80, 443, 8080. 8443, typically) for the URL. This will force the creation of an absolute URL when the current request's scheme does not match the value for this parameter. This is most often used in conjunction with scheme to switch to "https:443"/"https:8443" for secure portions of an application (such as a login page), before switching back to standard "http:80"/"http:80" for the majority of an application. | |
renderer | ILinkRenderer | no | The object which will actually render the link. | |
updateComponents | String[],Collection | no |
In an asynchronous request, specifies which components should have their content
rendered back to the client. These are expected to be unique component ids.
See: ResponseBuilder |
|
json | boolean | no | false | Causes the request to be asynchronous and the response to be captured/rendered via the JSONResponseBuilder renderer. |
async | boolean | no | false | Causes the request to be asynchronous and the response to be captured/rendered via the DojoAjaxResponseBuilder renderer. |
Body: rendered
Informal parameters: allowed
Reserved parameters: href
In this example the DirectLink component enables users to select a Customer from the Customer List table.
HTML template
<table cellspacing="6"> <tr> <td>ID</td> <td> </td> <td>Name</td> <td> </td> <td>Level</td> <th> </th> </tr> <tr> <td colspan="6"><hr></td> </tr> <tr jwcid="@Foreach" source="ognl:customerList" value="ognl:customer" element="tr"> <td><span jwcid="@Insert" value="ognl:customer.id"/></td> <td> </td> <td><span jwcid="@DirectLink" listener="listener:customerSelectAction" parameters="ognl:customer.id"> <span jwcid="@Insert" value="ognl:customer.fullName"/> </span></td> <td> </td> <td><span jwcid="@Insert" value="ognl:customer.memberLevel"/></td> <td> <a jwcid="@DirectLink" listener="listener.customerDeleteAction" parameters="ognl:customer.id" onclick="return window.confirm('Are you sure you want remove this customer?');"> <img jwcid="@Image" image="ognl:assets.deleteImage" alt="Delete"/> </a> </td> </tr> </table>
Page specification
<property name="customerList" type="java.util.List" persistent="yes"/> <property name="customer" type="Customer"/>
Java sources
public abstract class SalesPage extends BasePage { public abstract List getCustomerList(); public abstract List setCustomerList(List value); public abstract Customer getCustomer(); public void customerSelectAction(Integer id) { Visit visit = (Visit) getVisit(); Customer customer = visit.findCustomerByPrimaryKey(id); // Perform some action with the selected customer. .. } public void customerDeleteAction(Integer id) { Visit visit = (Visit) getVisit(); Customer customer = visit.findCustomerByPrimaryKey(id); visit.deleteCustomer(customer); } }
public class Visit() implements Serializable { public List getCustomerList() { List customerList = new ArrayList(); // Perform a database query retrieving the list of customers. .. return customerList; } public Customer findCustomerByPrimaryKey(Integer id) { Customer customer = null; // Retrieve the customer from the database with given the customer ID. .. return customer; } public void deleteCustomer(Customer customer) { // Delete customer from the database. .. } }
public class Customer implements Serializable { private Integer id; private String fullName; private String memberLevel; public Customer(Integer id, String fullName, String memberLevel) { this.id = id; this.fullName = fullName; this.memberLevel = memberLevel; } public Integer getId() { return id; } public String getFullName() { return fullName; } public String getMemberLevel() { return memberLevel; } }