001 // Copyright 2008 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 015 package org.apache.tapestry5.corelib.components; 016 017 import org.apache.tapestry5.BindingConstants; 018 import org.apache.tapestry5.ComponentResources; 019 import org.apache.tapestry5.Link; 020 import org.apache.tapestry5.annotations.Parameter; 021 import org.apache.tapestry5.corelib.base.AbstractComponentEventLink; 022 import org.apache.tapestry5.ioc.annotations.Inject; 023 024 /** 025 * A close relative of {@link org.apache.tapestry5.corelib.components.ActionLink} except in two ways. 026 * <p/> 027 * First, the event that it triggers is explicitly controlled, rather than always "action". 028 * <p/> 029 * Second, the event is triggered in its container. 030 * <p/> 031 * This allows slightly shorter URLs but also allows multiple components within the same container to generate identical 032 * URLs for common actions. 033 * @tapestrydoc 034 */ 035 public class EventLink extends AbstractComponentEventLink 036 { 037 /** 038 * The name of the event to be triggered in the parent component. Defaults to the id of the component. An {@link 039 * org.apache.tapestry5.corelib.components.ActionLink} triggers an "action" event on itself, and EventLink component 040 * triggers any arbitrary event on <em>its container</em>. 041 */ 042 @Parameter(defaultPrefix = BindingConstants.LITERAL) 043 private String event; 044 045 @Inject 046 private ComponentResources resources; 047 048 String defaultEvent() 049 { 050 return resources.getId(); 051 } 052 053 @Override 054 protected Link createLink(Object[] eventContext) 055 { 056 ComponentResources containerResources = resources.getContainerResources(); 057 058 return containerResources.createEventLink(event, eventContext); 059 } 060 }