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 * // -> アクション(FooAction)の @RequestParameter で修飾されたプロパティにバインドします。
40 * // よく使用するパターンです。
41 * public ActionResult m01() {
42 * }
43 *
44 * // -> アクション(FooAction)の @RequestParameter で修飾されたプロパティにバインドします。
45 * @Form(bindingType = ONLY_SPECIFIED_PROPERTIES)
46 * public ActionResult m02() {
47 * }
48 *
49 * // -> アクション(FooAction)の全プロパティにバインドします。
50 * @Form(bindingType = ALL_PROPERTIES)
51 * public ActionResult m03() {
52 * }
53 *
54 * // リクエストパラメータを barDto の全プロパティにバインドします。
55 * // よく使用するパターンです。
56 * @Form("barDto")
57 * public ActionResult m11() {
58 * }
59 *
60 * // リクエストパラメータを barDto の @RequestParameter で修飾されたプロパティにバインドします。
61 * @Form("barDto"
62 * bindingType = ONLY_SPECIFIED_PROPERTIES)
63 * public ActionResult m12() {
64 * }
65 *
66 * // リクエストパラメータを barDto の全プロパティにバインドします。
67 * @Form(value = "barDto",
68 * bindingType = ALL_PROPERTIES)
69 * public ActionResult m13() {
70 * }
71 *
72 * // リクエストパラメータをバインドしません。
73 * @Form(bindingType = NONE)
74 * public ActionResult m21() {
75 * }
76 * }
77 * </pre>
78 *
79 * </p>
80 *
81 * <p>
82 * クラスとメソッドの両方に注釈をつけた場合は、メソッドの注釈が優先されます。
83 *
84 * <pre>
85 * @Form("barDto")
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 * @Form("bazDto")
98 * // リクエストパラメータを bazDto のプロパティにバインドします(アクションメソッドでの指定が優先されるため)。
99 * public ActionResult m02() {
100 * }
101 * }
102 * </pre>
103 *
104 * </p>
105 *
106 * <p>
107 * このアノテーションをつけない場合の挙動が 1.0.x と 1.1.x で異なるのでご注意ください。
108 * <table>
109 * <thead>
110 * <tr>
111 * <th>バージョン</th>
112 * <th>バインド対象のオブジェクト</th>
113 * <th>バインド対象のプロパティ</th>
114 * </tr>
115 * </thead> <tbody>
116 * <tr>
117 * <td>1.0.x</td>
118 * <td>アクション</td>
119 * <td>すべてのプロパティ</td>
120 * </tr>
121 * <tr>
122 * <td>1.1.x</td>
123 * <td>アクション</td>
124 * <td>@RequestParameter で修飾されたプロパティ</td>
125 * </tr>
126 * </tbody>
127 * </table>
128 * </p>
129 *
130 * @author agata
131 * @since 1.0.0
132 * @see RequestParameter
133 * @see RequestParameterBindingType
134 */
135 @Retention(RetentionPolicy.RUNTIME)
136 @Target( { ElementType.METHOD, ElementType.TYPE })
137 public @interface Form {
138 /** アクションメソッド自身にリクエストパラメータがバインディングされることを表します */
139 public static final String THIS = "this";
140
141 /**
142 * バインディングするオブジェクトのプロパティ名。
143 * <p>
144 * "this" が指定された場合は、アクションクラス自身にリクエストパラメータがバインディングされることを表します。
145 * </p>
146 */
147 String value() default THIS;
148
149 /**
150 * リクエストパラメータからフォームオブジェクトへのバインディング方法を指定します。
151 *
152 * @since 1.1.0
153 */
154 RequestParameterBindingType bindingType() default ALL_PROPERTIES;
155
156 }