View Javadoc

1   /*
2    * Copyright 2004-2009 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.action;
17  
18  import static org.seasar.cubby.action.RequestParameterBindingType.ALL_PROPERTIES;
19  
20  import java.lang.annotation.ElementType;
21  import java.lang.annotation.Retention;
22  import java.lang.annotation.RetentionPolicy;
23  import java.lang.annotation.Target;
24  
25  /**
26   * アクションメソッド呼び出し時に要求パラメータがバインドされるオブジェクトや方法を指定します。
27   * 
28   * <p>
29   * この注釈によって、どのように要求パラメータがバインドされるかが変わります。
30   * 
31   * <pre>
32   * import static org.seasar.cubby.action.RequestParameterBindingType.*;
33   * 
34   * public class FooAction {
35   * 
36   * 	// コンテナの機能によって自動的にインジェクションされる想定です。
37   * 	public BarDto barDto;
38   * 
39   * 	// -&gt; アクション(FooAction)の @RequestParameter で修飾されたプロパティとフィールドにバインドします。
40   *  // よく使用するパターンです。
41   * 	public ActionResult m01() {
42   * 	}
43   * 
44   * 	// -&gt; アクション(FooAction)の @RequestParameter で修飾されたプロパティとフィールドにバインドします。
45   * 	&#064;Form(bindingType = ONLY_SPECIFIED_PROPERTIES)
46   * 	public ActionResult m02() {
47   * 	}
48   * 
49   * 	// -&gt; アクション(FooAction)のすべてのプロパティにバインドします。フィールドにはバインドしません。
50   * 	&#064;Form(bindingType = ALL_PROPERTIES)
51   * 	public ActionResult m03() {
52   * 	}
53   * 
54   * 	// -&gt; 要求パラメータを barDto の全プロパティにバインドします。フィールドにはバインドしません。
55   *  // よく使用するパターンです。
56   * 	&#064;Form(&quot;barDto&quot;)
57   * 	public ActionResult m11() {
58   * 	}
59   * 
60   * 	// 要求パラメータを barDto の @RequestParameter で修飾されたプロパティとフィールドにバインドします。
61   * 	&#064;Form(&quot;barDto&quot;
62   *             bindingType = ONLY_SPECIFIED_PROPERTIES)
63   * 	public ActionResult m12() {
64   * 	}
65   * 
66   * 	// 要求パラメータを barDto の全プロパティにバインドします。フィールドにはバインドしません。
67   * 	&#064;Form(value = &quot;barDto&quot;,
68   *             bindingType = ALL_PROPERTIES)
69   * 	public ActionResult m13() {
70   * 	}
71   * 
72   * 	// 要求パラメータをバインドしません。
73   * 	&#064;Form(bindingType = NONE)
74   * 	public ActionResult m21() {
75   * 	}
76   * }
77   * </pre>
78   * 
79   * </p>
80   * 
81   * <p>
82   * クラスとメソッドの両方に注釈をつけた場合は、メソッドの注釈が優先されます。
83   * 
84   * <pre>
85   * &#064;Form(&quot;barDto&quot;)
86   * // 全アクションメソッドに対して一括でバインディングの指定を行います。
87   * public class Foo2Action {
88   * 
89   * 	public BarDto barDto;
90   * 
91   * 	public BazDto bazDto;
92   * 
93   * 	// 要求パラメータを barDto のプロパティにバインドします (クラスでの指定が有効なため)。
94   * 	public ActionResult m01() {
95   * 	}
96   * 
97   * 	&#064;Form(&quot;bazDto&quot;)
98   * 	// 要求パラメータを bazDto のプロパティにバインドします(アクションメソッドでの指定が優先されるため)。
99   * 	public ActionResult m02() {
100  * 	}
101  * }
102  * </pre>
103  * 
104  * </p>
105  * 
106  * @author agata
107  * @see RequestParameter
108  * @see RequestParameterBindingType
109  */
110 @Retention(RetentionPolicy.RUNTIME)
111 @Target( { ElementType.METHOD, ElementType.TYPE })
112 public @interface Form {
113 	/** アクションメソッド自身に要求パラメータがバインディングされることを表します */
114 	public static final String THIS = "this";
115 
116 	/**
117 	 * バインディングするオブジェクトのプロパティ名。
118 	 * <p>
119 	 * "this" が指定された場合は、アクションクラス自身に要求パラメータがバインディングされることを表します。
120 	 * </p>
121 	 */
122 	String value() default THIS;
123 
124 	/**
125 	 * 要求パラメータからフォームオブジェクトへのバインディング方法を指定します。
126 	 */
127 	RequestParameterBindingType bindingType() default ALL_PROPERTIES;
128 
129 }