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