001// Copyright 2009 , 2010 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.annotations;
016
017import java.lang.annotation.Target;
018import java.lang.annotation.ElementType;
019import java.lang.annotation.Retention;
020import java.lang.annotation.RetentionPolicy;
021
022import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.MIXIN;
023
024import org.apache.tapestry5.internal.transform.BindParameterWorker;
025import org.apache.tapestry5.ioc.annotations.UseWith;
026
027/**
028 * Designates a field in a mixin which is bound to the parameter of the containing
029 * component corresponding to the value of the annotation. If no value is specified,
030 * the bound parameter name is assumed to match the field name of the mixin.
031 * For example, a mixin intended to work with form fields would define a field named
032 * "value", marked by this annotation. The user-variable bound to the component's value
033 * parameter would ultimately be bound in a chain:
034 * uservariable <=> mixin.value <=> component.value.
035 * Changes to any one value in the chain will be propagated accordingly.
036 * 
037 * @since 5.2.0
038 * @see BindParameterWorker
039 */
040@Target(ElementType.FIELD)
041@Retention(RetentionPolicy.RUNTIME)
042@UseWith(MIXIN)
043public @interface BindParameter
044{
045
046    /**
047     * @return the name of the mixin bound-parameter, exactly as for the Parameter annotation.
048     */
049    String name() default "";
050
051    /**
052     * @return the name(s) of the parent parameter to bind. Defaults to the name of the mixin field.
053     *         If more than one
054     *         name is specified, the first name matching a declared parameter of the core component
055     *         will be used.
056     */
057    String[] value() default
058    { "" };
059}