001 // Copyright 2007, 2008, 2011 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.MarkupWriter; 021 import org.apache.tapestry5.annotations.Parameter; 022 import org.apache.tapestry5.corelib.base.AbstractLink; 023 import org.apache.tapestry5.ioc.annotations.Inject; 024 025 /** 026 * Generates a render request link to some other page in the application. If an activation context is supplied (as the 027 * context parameter), then the context values will be encoded into the URL. If no context is supplied, then the target 028 * page itself will supply the context via a passivate event. 029 * <p/> 030 * Pages are not required to have an activation context. When a page does have an activation context, the value 031 * typically represents the identity of some object displayed or otherwise manipulated by the page. 032 * 033 * @tapestrydoc 034 */ 035 public class PageLink extends AbstractLink 036 { 037 /** 038 * The logical name of the page to link to. 039 */ 040 @Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL) 041 private String page; 042 043 @Inject 044 private ComponentResources resources; 045 046 /** 047 * If provided, this is the activation context for the target page (the information will be encoded into the URL). 048 * If not provided, then the target page will provide its own activation context. 049 */ 050 @Parameter 051 private Object[] context; 052 053 void beginRender(MarkupWriter writer) 054 { 055 if (isDisabled()) return; 056 057 Link link = resources.createPageLink(page, resources.isBound("context"), context); 058 059 writeLink(writer, link); 060 } 061 062 void afterRender(MarkupWriter writer) 063 { 064 if (isDisabled()) return; 065 066 writer.end(); // <a> 067 } 068 }