Delegator Component Index ExceptionDisplay

DirectLink
net.sf.tapestry.link.DirectLink
Direct Link
 
Description
Creates a <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. This is used in cases where the ActionLink component can't be used (or is too inefficient).

See the Developers Guide ActionLink and DirectLink listeners for a more complete description.

Prior to release 2.2, this component was named Direct.

See Also
ActionLink, ExternalLink, GenericLink, PageLink, ServiceLink
Parameters
Name Type Direction Required Default Description
listener IActionListener in 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
in 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 using IRequestCycle.getServiceParameters().

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 DataSqueezer for more details.

disabled boolean in 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 in 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.
scheme String in no   If specified, then a longer URL (including scheme, server and possibly port) is generated using the specified scheme. Server is determined fromt he incoming request, and port is deterimined from the port paramter or the incoming request.
port int in no   If specified, then a longer URL (including scheme, server and port) is generated using the specified port. The server is determined from the incoming request, the scheme from the scheme parameter or the incoming request.
anchor String in no   The name of an anchor or element to link to. The final URL will have '#' and the anchor appended to it.

Body: rendered
Informal parameters: allowed
Reserved parameters: "href"

Examples

In this example the DirectLink component enables users to select or delete Customers from a Customer List table.

ID   Name   Level  

10276   Ms Sophie L. Jamies   Platinum Delete
10539   Mr Albert H. Davies   Gold Delete
10552   Mrs Jan S. Flawson   Gold Delete
10863   Mr Robert J. Hassel   Silver Delete

<table cellspacing="6">
  <tr>
   <td>ID</td>
   <td>&nbsp;</td>
   <td>Name</td>
   <td>&nbsp;</td>
   <td>Level</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td colspan="6"><hr></td>
  </tr>
 <span jwcid="foreachCustomer">
  <tr>
   <td><span jwcid="insertId"/></td>
   <td>&nbsp;</td>
   <td><a jwcid="customerSelectLink"> <span jwcid="insertFullName"/> </a></td>
   <td>&nbsp;</td>
   <td><span jwcid="insertMemberLevel"/></td>
   <td>
    <a jwcid="customerDeleteLink" onclick="return window.confirm('Are you sure you want remove this customer?');"> 
     <img jwcid="deleteImage" alt="Delete"/> 
    </a>
   </td>
  </tr>
 </span>
</table>


<component id="foreachCustomer" type="Foreach">
    <binding name="source" expression="visit.customerList"/>
    <binding name="value" expression="customer"/>
</component>

<component id="customerSelectLink" type="DirectLink">
    <binding name="listener" expression="listeners.customerSelectAction"/>
    <binding name="parameters" expression="customer.id"/>
</component>

<component id="customerDeleteLink" type="DirectLink">
    <binding name="listener" expression="listeners.customerDeleteAction"/>
    <binding name="parameters" expression="customer.id"/>
</component>

<component id="insertId" type="Insert">
    <binding name="value" expression="customer.id"/>
</component>

<component id="insertFullName" type="Insert">
    <binding name="value" expression="customer.fullName"/>
</component>

<component id="insertMemberLevel" type="Insert">
    <binding name="value" expression="customer.memberLevel"/>
</component>

<component id="imageDelete" type="Image"/>
    <binding name="image" expression="assets.deleteImage"//>
</component/>

<private-asset name="deleteImage" resource-path="/com/mycorp/delete.gif"/>


package com.mycorp; 

public class SalesPage extends BasePage {
    private Customer customer;
	 
    public Customer getCustomer() { return customer; }

    public void setCustomer(Customer value) {
        customer = value;
    }
    
    public void customerSelectAction(IRequestCycle cycle) {
        Visit visit = (Visit) getVisit();        
        Object[] parameters = cycle.getServiceParameters();
        Customer customer = visit.findCustomerByPrimaryKey((Integer) parameters[0]);
        // Perform some action with the selected customer.
        ..
    }

    public void customerDeleteAction(IRequestCycle cycle) {
        Visit visit = (Visit) getVisit();        
        Object[] parameters = cycle.getServiceParameters();
        Customer customer = visit.findCustomerByPrimaryKey((Integer) parameters[0]);
        visit.deleteCustomer(customer);
    }

    public void detach() {
        customer = null;
        super.detach();
    }
}

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 {
    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; }
}

Delegator Component Index ExceptionDisplay