    001// Copyright 2008, 2013 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007//     http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.corelib.components;
    016
    017import org.apache.tapestry5.BindingConstants;
    018import org.apache.tapestry5.ComponentResources;
    019import org.apache.tapestry5.Link;
    020import org.apache.tapestry5.annotations.Parameter;
    021import org.apache.tapestry5.corelib.base.AbstractComponentEventLink;
    022
    023/**
    024 * A close relative of {@link org.apache.tapestry5.corelib.components.ActionLink} except in two ways.
    025 * <p/>
    026 * First, the event that it triggers is explicitly controlled, rather than always "action".
    027 * <p/>
    028 * Second, the event is triggered in its container.
    029 * <p/>
    030 * This allows slightly shorter URLs but also allows multiple components within the same container to generate identical
    031 * URLs for common actions.
    032 * @tapestrydoc
    033 */
    034public class EventLink extends AbstractComponentEventLink
    035{
    036    /**
    037     * The name of the event to be triggered in the parent component. Defaults to the id of the component. An {@link
    038     * org.apache.tapestry5.corelib.components.ActionLink} triggers an "action" event on itself, and EventLink component
    039     * triggers any arbitrary event on <em>its container</em>.
    040     */
    041    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    042    private String event;
    043
    044    String defaultEvent()
    045    {
    046        return resources.getId();
    047    }
    048
    049    @Override
    050    protected Link createLink(Object[] eventContext)
    051    {
    052        ComponentResources containerResources = resources.getContainerResources();
    053
    054        return containerResources.createEventLink(event, eventContext);
    055    }
    056}