001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.hayabusa.taglib;
017
018import org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.common.HybsSystemException;
020import org.opengion.fukurou.util.XHTMLTag;
021
022import static org.opengion.fukurou.util.StringUtil.nval ;
023
024/**
025 * 入力フィールドやボタンなどを作成するHTML拡張タグです。
026 *
027 * 簡易的な入力用タグとして、columnタグがありますので、通常は、columnタグをお使い下さい。
028 * name 属性に ラベルリソース のキーを与えることで、ロケールにあわせたリソースを
029 * 使用して、画面に表示します。
030 * ロケールは、session 登録項目の HybsSystem#LANG_KEY を初期値で使用し、
031 * language 属性で定義されている場合は、そちらを優先します。
032 *
033 * @og.formSample
034 * ●形式:<og:input name=… value=… />
035 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します)
036 *
037 * ●Tag定義:
038 *   <og:input
039 *       type               【HTML】表示形式[text/password/checkbox/radio/submit/reset/button/image/file]を指定します(初期値:text)
040 *                                  HTML5追加分[search/tel/url/email/datetime/date/month/week/time/datetime-local/number/range/color]
041 *       name               【HTML】名前を指定します
042 *       value              【HTML】このフィールドに設定する値を指定します
043 *       caseKey            【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null)
044 *       caseVal            【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null)
045 *       caseNN             【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:true)
046 *       caseNull           【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:true)
047 *       lbl                【TAG】ラベルリソースのラベルIDを指定します
048 *       lbls               【TAG】ラベルをCSV形式で複数指定します
049 *       td                 【TAG】テーブル形式の <td> タグを使用するかどうか[yes/no/false]を指定します(初期値:yes)
050 *       colspan            【TAG】フィールド部分の colspan を指定します
051 *       nextForm           【TAG】入力カーソルを指定されたname属性のフィールドへ自動的に移動します
052 *       optionAttributes   【TAG】JavaScript などの HTML基本タグ以外の属性を、そのままタグとして使用します
053 *       must               【TAG】必須入力を表す色に変えるかどうか[true/false]を指定します(初期値:false)
054 *       mustAny            【TAG】選択必須入力(どれかひとつ必須)を表す色[true/mustAny/その他]を指定します(初期値:無指定)
055 *       aimai              【TAG】曖昧検索可能フィールドとして、曖昧検索方法を指定します(初期値:null)
056 *       size               【HTML】横幅を指定します(typeがtextまたはpasswordの場合は文字数で、それ以外はピクセル)
057 *       maxlength          【HTML】最大入力文字数を指定します(typeがtextまたはpasswordの場合)
058 *       checked            【HTML】type が checkbox か radio のとき、初めから選択された状態で表示します("checked"のみ指定可)
059 *       src                【HTML】type が image の場合、送信ボタンとして利用する画像のURLをセットします
060 *       alt                【HTML】type が image の場合で、画像が表示できない場合の代替テキストをセットします
061 *       accept             【HTML】type が file の場合に、MIMEタイプをCSV形式で複数指定出来ます
062 *       usemap             【HTML】type が image の場合、クライアントサイド・イメージマップのURLを指定します
063 *       ismap              【HTML】type が image の場合に、サーバーサイド・イメージマップを使用する場合に指定します
064 *       id                 【HTML】要素に対して固有の名前(id)をつける場合に設定します
065 *       lang               【HTML】要素の内容と他の属性値の言語(lang,xml:lang)を指定します
066 *       dir                【HTML】文字表記の方向(dir)を指定します
067 *       title              【HTML】要素に対する補足的情報(title)を設定します
068 *       style              【HTML】この要素に対して適用させるスタイルシート(style)を設定します
069 *       readonly           【TAG】その部品に対して変更が出来ないように(readonly)指定します(サーバーに送信される)
070 *       disabled           【TAG】その部品に対して、選択や変更が出来ないように(disabled)指定します(サーバーに送信されない)
071 *       tabindex           【HTML】タブの移動順(tabindex)を指定します(0 〜 32767)
072 *       accesskey          【HTML】アクセスキー(alt+キーで直接指定)を割り当てます
073 *       clazz              【HTML】要素に対して class 属性を設定します
074 *       language           【TAG】タグ内部で使用する言語コード[ja/en/zh/…]を指定します
075 *       onClick            【HTML】JavaScriptのイベント onClick を設定します(例:onClick="renew('query.jsp','QUERY');")
076 *       onChange           【HTML】JavaScriptのイベント onChange を設定します(例:onChange="renew('query.jsp','QUERY');")
077 *       onBlur             【HTML】JavaScriptのイベント onBlur を設定します(例:onBlur="this.value=value.toUpperCase();")
078 *       onFocus            【HTML】JavaScriptのイベント onFocus を設定します
079 *       ondblClick         【HTML】JavaScriptのイベント ondblClick を設定します
080 *       onMouseDown        【HTML】JavaScriptのイベント onMouseDown を設定します
081 *       onMouseUp          【HTML】JavaScriptのイベント onMouseUp を設定します
082 *       onMouseMove        【HTML】JavaScriptのイベント onMouseMove を設定します
083 *       onMouseOut         【HTML】JavaScriptのイベント onMouseOut を設定します
084 *       onMouseOver        【HTML】JavaScriptのイベント onMouseOver を設定します
085 *       onSelect           【HTML】JavaScriptのイベント onSelect を設定します
086 *       onKeydown          【HTML】JavaScriptのイベント onKeydown を設定します
087 *       onKeypress         【HTML】JavaScriptのイベント onKeypress を設定します
088 *       onKeyup            【HTML】JavaScriptのイベント onKeyup を設定します
089 *       autocomplete       【HTML5】入力候補を提示して入力内容を自動補完する[on/off](初期値はon)。
090 *       autofocus          【HTML5】指定した入力欄にカーソルが当たって自動的にフォーカスされます。
091 *       pattern            【HTML5】正規表現で入力値のパターンを指定します。
092 *       placeholder        【HTML5】入力欄に初期表示する内容を指定します。
093 *       required           【HTML5】入力必須を指定します
094 *       list               【HTML5】ユーザーに入力候補として提案するデータリストの要素のid属性の値を指定します。
095 *       min                【HTML5】入力欄で入力できる最小値を指定します。
096 *       max                【HTML5】入力欄で入力できる最大値を指定します。
097 *       step               【HTML5】入力欄で刻むステップ値を指定する。
098 *       roles              【TAG】ロールをセットします
099 *       useRealTimeCheck       【TAG】リアルタイムチェックを行うかどうか(初期値:行う)
100 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
101 *   >   ... Body ...
102 *   </og:input>
103 *
104 * ●使用例
105 *    <og:input name="OYA" />                             lbl属性が指定されていない場合は、name属性をキーにしてLabelResourceを読み取ります。
106 *    <og:input name="PN" lbl="KO" />                     lbl属性を指定することで、ラベルだけを付替えることができます。
107 *    <og:input name="PN" size="13" maxlength="11" />     強制的にサイズの変更をするときは、size属性、maxlength属性を使用できます。
108 *    <og:input name="OYA" td="false" />                  自動作成されるtdタグやラベルを外すときはtd属性を使います。
109 *    <og:input name="OYA" td="no" />                     自動作成されるtdタグを外し、ラベルとフィールドは残します。
110 *    <og:input name="PN" optionAttributes="onBlur='blr()'
111 *                            onFocus='fcs()'" />
112 *                                                               JavaScriptのイベントをコーディングするときは、optionAttributes属性を使います。
113 *    <og:input type="radio" name="OYA" />                ラベル部分と入力フィールド部分がテーブルタグの<td>により左右に分割されます。
114 *
115 *    <table>
116 *        <tr><og:input name="PN" value="{@PN}" /></tr>
117 *        <tr><og:input name="CD" value="{@CD}" /></tr>
118 *    </table>
119 *
120 *    <table>
121 *        <tr><og:input name="PN" value="{@PN}" >部品入力フィールド</og:input></tr>
122 *        <tr><og:input name="CD" value="{@CD}" >コードフィールド</og:input></tr>
123 *    </table>
124 *                                                               HTML 表示時は、前後に<tr>タグで囲って,整形できます。
125 *
126 *    <og:input name="A"  nextForm="B" />                最大桁数入力後、フォーム B にフォーカスが移動します。
127 *    <og:input name="B" />
128 *
129 *    BODY 部分に記述した値は、入力フィールドの直後にセットされます。
130 *    <og:input name="PN" >
131 *      <button type="button" onclick="popup(・・・);return false;">
132 *          <og:message lbl="POPUP" comment="▼" />
133 *      </button>
134 *    </og:input>
135 *
136 * @og.group 画面部品
137 *
138 * @version  4.0
139 * @author   Kazuhiko Hasegawa
140 * @since    JDK5.0,
141 */
142public class InputTag extends HTMLTagSupport {
143        //* このプログラムのVERSION文字列を設定します。   {@value} */
144        private static final String VERSION = "5.7.1.0 (2013/12/06)" ;
145
146        private static final long serialVersionUID = 571020131206L ;
147
148        // 5.7.1.0 (2013/12/06) HTML5 で新たに追加された、type を追加
149//      private static final String CHECK_TYPE = "|text|password|checkbox|radio|submit|reset|button|image|file|hidden|" ;
150        private static final String CHECK_TYPE = "|text|password|checkbox|radio|submit|reset|button|image|file|hidden|" 
151                                                                        + "search|tel|url|email|datetime|date|month|week|time|datetime-local|number|range|color|" ;
152
153        // 4.0.0 (2005/01/31) HTML_LABEL_SEPARATOR を boolean 変数として取得します。
154        private final String CLM = ( HybsSystem.sysBool( "HTML_LABEL_SEPARATOR" ) ) ? ":" : "" ;
155
156        private String  td_flag         = "yes";        // yes:<td> タグを使用 / false:フィールドのみ / no:ラベルとフィールド
157        // 3.0.1.4 (2003/03/17) colspan 属性を追加。
158        private String  colspan     = "";
159        // 3.5.4.2 (2003/12/15) nextForm 属性を追加。
160        private String  nextForm    = null;
161
162        // 4.0.0 (2005/01/31) COLUMNS_MAXSIZE を定義しておきます。
163        private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ;   // 表示フィールドの大きさ
164
165        // 4.0.0 (2007/05/30) BODY 部分に記述した値は、入力フィールドの直後にセットされます。
166        private String  body            = null;
167
168        /**
169         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
170         *
171         * @og.rev 4.0.0.0 (2007/05/30) 新規追加(BODY部の評価)
172         * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
173         *
174         * @return      後続処理の指示( EVAL_BODY_BUFFERED )
175         */
176        @Override
177        public int doStartTag() {
178                // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
179                if( useTag() ) {
180                        return( EVAL_BODY_BUFFERED );   // Body を評価する。( extends BodyTagSupport 時)
181                }
182                return ( SKIP_BODY );                           // Body を評価しない
183        }
184
185        /**
186         * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。
187         *
188         * @og.rev 4.0.0.0 (2007/05/30) 新規追加(BODY部の評価)
189         *
190         * @return      後続処理の指示(SKIP_BODY)
191         */
192        @Override
193        public int doAfterBody() {
194                body = getBodyString();
195                return(SKIP_BODY);
196        }
197
198        /**
199         * タグリブオブジェクトをリリースします。
200         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
201         *
202         * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加
203         * @og.rev 2.0.0.8 (2002/10/09) yes/no/false で指定するように変更
204         * @og.rev 3.0.1.4 (2003/03/17) colspan 属性を追加。
205         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
206         * @og.rev 3.5.4.2 (2003/12/15) nextForm 属性を追加。
207         * @og.rev 5.8.7.1 (2015/05/22) body追加(6.2.4.0対応)
208         */
209        @Override
210        protected void release2() {
211                super.release2();
212                td_flag         = "yes";        // table形式の <td> タグを使用するかどうか
213                colspan         = "";
214                nextForm        = null;         // 3.5.4.2 (2003/12/15)
215                body            = null;         // 5.8.7.1 (2015/05/22)
216        }
217
218        /**
219         * 検索条件の入力用のテキストフィールドを作成します。
220         *
221         * テーブルタグによりフィールドは分割されます。
222         * 使用時は、テーブルタグを前後に使用して下さい。
223         *
224         * @og.rev 2.0.0.8 (2002/10/09) yes/no/false で指定するように変更
225         * @og.rev 2.0.1.0 (2002/10/10) ラベルとフィールドのセパレーターとして、コロン(:)を使用するかどうかを指定できる
226         * @og.rev 3.0.1.2 (2003/03/07) forward.jsp の代替用 CommonForwardTag を新規作成
227         * @og.rev 3.1.0.1 (2003/03/26) キャッシュエントリーは、type="submit" の場合のみ、登録する。
228         * @og.rev 3.1.1.0 (2003/03/28) forward.jsp 関係の処理を削除する。
229         * @og.rev 3.1.1.0 (2003/03/28) radio ボタン等で、ラベルをクリックしても値をセットできるようにする。
230         * @og.rev 3.5.4.2 (2003/12/15) 入力カーソルを自動的に次のフィールドへ移動する機能を追加する。
231         * @og.rev 4.0.0.0 (2007/05/30) BODY 部分に記述した値は、入力フィールドの直後にセットされます。
232         * @og.rev 4.3.7.1 (2009/06/08) id=labelのclass化
233         * @og.rev 5.2.1.0 (2010/10/01) must , mustAny 属性を自動化します。
234         * @og.rev 5.6.2.2 (2013/03/15) 自動must処理の出力位置を変更
235         * @og.rev 5.8.4.1 (2015/02/10) aimai対応 6.2.0.0逆移植
236         *
237         * @return  入力用のテキストフィールドタグ
238         */
239        @Override
240        protected String makeTag() {
241                if( get( "value" ) == null ) { set( "value","" ); }
242                if( getMsglbl() == null ) { setLbl( get( "name" ) ); }
243
244                // 3.5.4.2 (2003/12/15) 入力カーソルを自動的に次のフィールドへ移動する機能
245                if( nextForm != null ) {
246                        String onKeyup = "nextForm(this,'" + nextForm + "'," + get( "maxlength" ) + ");" ;
247                        set( "onKeyup",onKeyup );
248                }
249
250                String type = get( "type" );
251                StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
252                // もう少しましな、別の方法を考える必要があります。
253                if( "yes".equals( td_flag ) ) {
254                        if( type != null && ( "radio".equals( type ) || "checkbox".equals( type ) )) {
255                                if( get( "id" ) == null ) { set( "id",TaglibUtil.getTagId() ); }
256
257                                rtn.append( "<td>" );
258                                rtn.append( XHTMLTag.input( getAttributes() ) );
259                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
260                                rtn.append( "</td>" );
261                                rtn.append( "<td " );
262                                rtn.append( colspan );
263                                rtn.append( ">" );
264                                rtn.append( "<label for=\"" );
265                                rtn.append( get( "id" ) );
266                                rtn.append( "\">" );
267                                rtn.append( getLongLabel() );           // 4.0.0 (2005/01/31)
268                                rtn.append( "</label>" );
269//                              rtn.append( "</td>" );
270                        }
271                        else if( type != null && ( "submit".equals( type ) || "reset".equals( type ) || "button".equals( type ) ) ) {
272                                set( "value",getMsglbl() );
273                                rtn.append( "<td" );
274                                rtn.append( colspan );
275                                rtn.append( ">" );
276                                rtn.append( XHTMLTag.input( getAttributes() ) );
277                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
278                                rtn.append( "</td>" );
279//                              rtn.append( "<td></td>" );
280                                rtn.append( "<td>" );
281                        }
282                        else {
283                                // 4.3.7.1 (2009/06/08) id=labelのclass化
284                                // rtn.append( "<td id=\"label\">" );
285                                rtn.append( "<td class=\"label\">" );
286                                rtn.append( getLongLabel() );           // 4.0.0 (2005/01/31)
287                                rtn.append( CLM );
288                                rtn.append( "</td>" );
289                                rtn.append( "<td" );
290                                rtn.append( colspan );
291                                rtn.append( ">" );
292                                rtn.append( XHTMLTag.input( getAttributes() ) );
293                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
294//                              rtn.append( "</td>" );
295                        }
296                        rtn.append( makeAimaiPicker( get("name") ) ); // 5.8.4.2(2015/02/20)
297                        if( getMustType() != null ) { rtn.append( makeMustHidden( get( "name" ) ) ); } // 5.6.2.2 (2013/03/15)
298                        rtn.append( "</td>" );
299                }
300                else if( "no".equals( td_flag ) ) {
301                        if( type != null && ( "radio".equals( type ) || "checkbox".equals( type ) )) {
302                                rtn.append( "<label>" );
303                                rtn.append( XHTMLTag.input( getAttributes() ) );
304                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
305                                // 4.3.7.1 (2009/06/08) id=labelのclass化
306                                // rtn.append( "<span id=\"label\">" );
307                                rtn.append( "<span class=\"label\">" );
308                                rtn.append( getLongLabel() );           // 4.0.0 (2005/01/31)
309                                rtn.append( "</span>" );
310                                rtn.append( "</label>" );
311                        }
312                        else if( type != null && ( "submit".equals( type ) || "reset".equals( type ) || "button".equals( type ) ) ) {
313                                set( "value",getMsglbl() );
314                                rtn.append( XHTMLTag.input( getAttributes() ) );
315                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
316                        }
317                        else {
318                                // 4.3.7.1 (2009/06/08) id=labelのclass化
319                                // rtn.append( "<span id=\"label\">" );
320                                rtn.append( "<span class=\"label\">" );
321                                rtn.append( getLongLabel() );           // 4.0.0 (2005/01/31)
322                                rtn.append( CLM );
323                                rtn.append( "</span>" );
324                                rtn.append( XHTMLTag.input( getAttributes() ) );
325                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
326                        }
327                        rtn.append( makeAimaiPicker( get("name") ) ); // 5.8.4.2(2015/02/20)
328                        if( getMustType() != null ) { rtn.append( makeMustHidden( get( "name" ) ) ); } // 5.6.2.2 (2013/03/15)
329                }
330                else {
331                        if( type != null && ( "submit".equals( type ) || "reset".equals( type ) || "button".equals( type ) ) ) {
332                                set( "value",getMsglbl() );
333                                rtn.append( XHTMLTag.input( getAttributes() ) );
334                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
335                        }
336                        else {
337                                rtn.append( XHTMLTag.input( getAttributes() ) );
338                                if( body != null ) { rtn.append( body ); }      // 4.0.0 (2007/05/30) BODY部の評価
339                        }
340                        rtn.append( makeAimaiPicker( get("name") ) ); // 5.8.4.2(2015/02/20)
341                        if( getMustType() != null ) { rtn.append( makeMustHidden( get( "name" ) ) ); } // 5.6.2.2 (2013/03/15)
342                }
343
344                // 5.2.1.0 (2010/10/01) must , mustAny 属性を自動化します。
345                // 5.6.2.2 (2013/03/15) tdの外に出力される不正形を正します
346//              if( getMustType() != null ) { rtn.append( makeMustHidden( get( "name" ) ) ); }
347
348                return rtn.toString() ;
349        }
350
351        /**
352         * 【HTML】名前を指定します。
353         *
354         * @og.tag
355         *  &lt;og:input name="PN" /&gt;
356         *
357         * @param   name 名前
358         */
359        public void setName( final String name ) {
360                set( "name",getRequestParameter( name ) );
361        }
362
363        /**
364         * 【HTML】表示形式を指定します(初期値:text)。
365         *
366         * @og.tag
367         * 通常は、表示形式[text/password/checkbox/radio/submit/reset/button/image/file]を指定します。
368         * HTML5 で追加された形式[search/tel/url/email/datetime/date/month/week/time/datetime-local/number/range/color]
369         * も、設定できます。
370         *
371         * HTML5 の機能を有効にするには、ネイティブモードで動作させる必要があります。
372         *   @ USE_IE7_HEADER = "false" に設定する。
373         *   A USE_HTML5_HEADER = "true" に設定する。
374         *   B IEのツール⇒互換表示設定で、互換表示に追加したWebサイトから削除する。
375         *   C 同上の設定で、イントラサイトを互換表示で表示するのチェックを外す。
376         * 必要があります。
377         *
378         * &lt;og:input type="text"     /&gt; テキストボックスを表示
379         * &lt;og:input type="password" /&gt; パスワード専用テキストボックスを表示
380         * &lt;og:input type="checkbox" /&gt; チェックボックスを表示
381         * &lt;og:input type="radio"    /&gt; ラジオボタンを表示
382         * &lt;og:input type="submit"   /&gt; 送信実行ボタンを表示
383         * &lt;og:input type="reset"    /&gt; 入力したフィールド内容を全てリセット
384         * &lt;og:input type="button"   /&gt; ボタンを表示
385         * &lt;og:input type="image"    /&gt; イメージを表示してクリックした座標を返す
386         * &lt;og:input type="file"     /&gt; ファイル名入力ボックスを表示
387         * &lt;og:input type="hidden"   /&gt; 表示させずにサーバーに送信するデータ
388         *
389         * HTML5 で追加されたタイプ
390         * &lt;og:input type="search"                       /&gt; 検索テキストの入力欄を作成する
391         * &lt;og:input type="tel"                          /&gt; 電話番号の入力欄を作成する
392         * &lt;og:input type="url"                          /&gt; URLの入力欄を作成する
393         * &lt;og:input type="email"                        /&gt; メールアドレスの入力欄を作成する
394         * &lt;og:input type="datetime"                     /&gt; UTC(協定世界時)による日時の入力欄を作成する
395         * &lt;og:input type="date"                         /&gt; 日付の入力欄を作成する
396         * &lt;og:input type="month"                        /&gt; 月の入力欄を作成する
397         * &lt;og:input type="week"                         /&gt; 週の入力欄を作成する
398         * &lt;og:input type="time"                         /&gt; 時間の入力欄を作成する
399         * &lt;og:input type="datetime-local"       /&gt; UTC(協定世界時)によらないローカル日時の入力欄を作成する
400         * &lt;og:input type="number"                       /&gt; 数値の入力欄を作成する
401         * &lt;og:input type="range"                        /&gt; レンジの入力欄を作成する
402         * &lt;og:input type="color"                        /&gt; 色の入力欄を作成する
403         *
404         * @og.rev 5.7.1.0 (2013/12/06) HTML5 対応
405         *
406         * @param   type 表示形式[text/password/checkbox/radio/submit/reset/button/image/file]、HTML5用 [search/tel/url/email/datetime/date/month/week/time/datetime-local/number/range/color]
407         */
408        public void setType( final String type ) {
409                String tp = getRequestParameter( type );
410
411                if( check( "|" + tp + "|" , CHECK_TYPE ) ) {
412                        set( "type",tp );
413                }
414                else {
415                        String errMsg = "type 属性は、下記の中から選択してください。type=["
416                                                 + tp + "  in [" + CHECK_TYPE + "]";
417                        throw new HybsSystemException( errMsg );
418                }
419        }
420
421        /**
422         * 【HTML】このフィールドに設定する値を指定します。
423         *
424         * @og.tag
425         * type属性の値が"radio"か"checkbox"以外の場合、この属性は省略可能です。
426         *&lt;og:input name="PN" value="syokichi" /&gt;
427         *
428         * @param   value 初期値
429         */
430        public void setValue( final String value ) {
431                set( "value",getRequestParameter( value ) );
432        }
433
434        /**
435         * 【HTML】横幅を指定します(typeがtextまたはpasswordの場合は文字数で、それ以外はピクセル)。
436         *
437         * @og.tag
438         *  &lt;og:input name="PN" size="20" /&gt;
439         *
440         * @param   size 横幅
441         */
442        public void setSize( final String size ) {
443                set( "size",getRequestParameter( size ) );
444        }
445
446        /**
447         * 【HTML】最大入力文字数を指定します(typeがtextまたはpasswordの場合)。
448         *
449         * @og.tag
450         * 最大文字数はsize指定を超え得るが、超えた場合ユーザエージェントはスクロール機構を提供する必要があります。
451         *この属性の初期値は「無制限」です。
452         *&lt;og:input name="PN" maxlength="20" /&gt;
453         *
454         * @og.rev 3.5.4.2 (2003/12/15) 最大入力制限数に応じたサイズ自動生成を入れます。
455         * @og.rev 3.5.4.5 (2004/01/23) CSSで処理する場合のクラス属性は、maxlength が 5 以下の場合とする。
456         * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動
457         *
458         * @param   maxlength 最大入力文字数
459         */
460        public void setMaxlength( final String maxlength ) {
461                String mlen = nval( getRequestParameter( maxlength ),null ) ;
462                set( "maxlength",mlen );
463                if( get( "size" ) == null && mlen != null ) {
464                        // 4.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動
465                        int size = Integer.parseInt( mlen );
466                        if( size > COLUMNS_MAXSIZE ) { size = COLUMNS_MAXSIZE; }
467                        set( "size",String.valueOf( size ) );
468                }
469
470                // 3.5.4.5 (2004/01/23) 追加
471                if( mlen != null && mlen.length() == 1 ) {
472                        char ch = mlen.charAt(0);
473                        if( ch >= '1' && ch <= '5' ) {
474                                add( "class", "S0" + ch );      // 3.5.5.9 (2004/06/07) セパレータ引数付きのメソッドに変更
475                        }
476                }
477        }
478
479        /**
480         * 【HTML】type が checkbox か radio のとき、初めから選択された状態で表示します("checked"のみ指定可)。
481         *
482         * @og.tag
483         *
484         * &lt;og:input name="PN" type="checkbox" checked="checked" /&gt;
485         *
486         * @param   ch 選択された状態にするかどうか[checked:選択状態/そのた:なにもしない]
487         */
488        public void setChecked( final String ch ) {
489                String checked = getRequestParameter( ch );
490                if( "checked".equals( checked )) {
491                        set( "checked","checked" );
492                }
493        }
494
495        /**
496         * 【HTML】type が image の場合、送信ボタンとして利用する画像のURLをセットします。
497         *
498         * @og.tag src セット
499         *
500         * @param   src 画像のURL
501         */
502        public void setSrc( final String src ) {
503                set( "src",getRequestParameter( src ) );
504        }
505
506        /**
507         * 【HTML】type が image の場合で、画像が表示できない場合の代替テキストをセットします。
508         *
509         * @og.tag alt セット
510         *
511         * @param   alt 代替テキスト
512         */
513        public void setAlt( final String alt ) {
514                set( "alt",getRequestParameter( alt ) );
515        }
516
517        /**
518         * 【HTML】type が file の場合に、MIMEタイプをCSV形式で複数指定出来ます。
519         *
520         * @og.tag accept セット
521         *
522         * @param   accept MIMEタイプ(CSV形式)
523         */
524        public void setAccept( final String accept ) {
525                set( "accept",getRequestParameter( accept ) );
526        }
527
528        /**
529         * 【HTML】type が image の場合、クライアントサイド・イメージマップのURLを指定します。
530         *
531         * @og.tag usemap セット
532         *
533         * @param   usemap クライアントサイド・イメージマップのURL
534         */
535        public void setUsemap( final String usemap ) {
536                set( "usemap",getRequestParameter( usemap ) );
537        }
538
539        /**
540         * 【HTML】type が image の場合に、サーバーサイド・イメージマップを使用する場合に指定します。
541         *
542         * @og.tag ismap セット
543         *
544         * @param   ismap サーバーサイド・イメージマップを使用する場合に指定
545         */
546        public void setIsmap( final String ismap ) {
547                set( "ismap",getRequestParameter( ismap ) );
548        }
549
550        /**
551         * 【TAG】テーブル形式の &lt;td&gt; タグを使用するかどうか[yes/no/false]を指定します(初期値:yes)。
552         *
553         * @og.tag
554         * 通常(初期値:yes)は、テーブル形式の&lt;td&gt; タグを使用して、ラベルとフィールドを整列させます。
555         * no の場合は、tdタグを使用せず、ラベルとフィールドを連続して出力します。
556         * false は、ラベルを出力せず、フィールドのみ出力します。
557         *  &lt;og:input name="PN" td="false" /&gt;
558         *
559         * @og.rev 2.0.0.8 (2002/10/09) yes/no/false で指定するように変更
560         *
561         * @param   flag [yes:tdタグを使用/no:ラベルとフィールド/false:フィールドのみ]
562         */
563        public void setTd( final String flag ) {
564                String td = nval( getRequestParameter( flag ),td_flag );
565
566                if( check( "|" + td + "|" , "|yes|no|false|" ) ) {
567                        td_flag = td;
568                }
569                else {
570                        String errMsg = "td 属性は、下記の中から選択してください。td=["
571                                                 + td  + "  in [|true|false|label|]";
572                        throw new HybsSystemException( errMsg );
573                }
574        }
575
576        /**
577         * 【TAG】ラベルをCSV形式で複数指定します。
578         *
579         * @og.tag
580         * シングルラベルの lbl 属性との違いは,ここではラベルを複数 カンマ区切りで
581         * 渡すことが可能であることです。これにより、"A,B,C" という値に対して、
582         * "Aのラベル表示,Bのラベル表示,Cのラベル表示" という具合に文字列を
583         * 再合成します。
584         * これは、SQL文のOrder By 句で、ソート順を指定する場合などに便利です。
585         *
586         *  &lt;og:orderBy columns="MKNMJP,MKCD,MKNMEN" lbls="MKNMJP,MKCD,MKNMEN" /&gt;
587         *
588         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
589         * @og.rev 5.2.2.0 (2010/11/01) setMsglbl 廃止 ⇒ setLbl に置換え
590         *
591         * @param   lbls 複数ラベルID(カンマ区切り)
592         */
593        public void setLbls( final String lbls ) {
594
595                String[] array = getCSVParameter( lbls );
596
597                StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
598
599                buf.append( getLabel( array[0] ) );
600                for( int i=1; i<array.length; i++ ) {
601                        buf.append( "," );
602                        buf.append( getLabel( array[i] ) );
603                }
604//              setMsglbl( buf.toString() );
605                setLbl( buf.toString() );               // 5.2.2.0 (2010/11/01) setMsglbl 廃止 ⇒ setLbl に置換え
606        }
607
608        /**
609         * 【TAG】フィールド部分の colspan を指定します。
610         *
611         * @og.tag
612         * 通常は、ラベルとフィールドが、別のtdで囲われます。しかし、場合によっては、
613         * フィールド部の長いカラムがある場合、上下のカラムとの位置関係がおかしくなり、
614         * ラベルとフィールドが離れて表示されるケースがあります。
615         * この場合、長いフィールド部を持つカラムに、colspan 属性を指定すると、
616         * その分のカラムを割り当てることにより、上下のカラムとの位置関係を
617         * 調節することが可能になります。
618         * 通常は、3 を指定して、フィールド、ラベル、フィールドの
619         * 組み合わせ部分に、長いフィールドが適用されるように使用します。
620         *
621         *  &lt;og:input name="PN" colspan="3" /&gt;
622         *
623         * @og.rev 3.0.1.4 (2003/03/17) colspan 属性を追加。
624         *
625         * @param   sp フィールド部分のcolspan
626         */
627        public void setColspan( final String sp ) {
628                colspan = nval( getRequestParameter( sp ),colspan );
629                if( colspan.length() > 0 ) {
630                        colspan = " colspan=\"" + colspan + "\" ";
631                }
632        }
633
634        /**
635         * 【TAG】入力カーソルを指定されたname属性のフィールドへ自動的に移動します。
636         *
637         * @og.tag
638         * JavaScript の onKeyup イベントを利用して、最大桁数まで入力すると、
639         * 次のフィールドに、自動的に飛ぶように設定します。
640         * 引数は、次に飛ばすフィールドの name 属性です。
641         * 実行するには、JavaScript の nextForm ファンクションが必要です。(default.js で指定)
642         *
643         * @og.rev 3.5.4.2 (2003/12/15) 新規追加
644         *
645         * @param   name 次にフォーカスを移すタグのname属性
646         */
647        public void setNextForm( final String name ) {
648                nextForm = nval( getRequestParameter( name ),nextForm );
649        }
650        
651        /**
652         * 【TAG】リアルタイムチェックを行わない指定。
653         *
654         * @og.tag
655         * カラム単位でリアルタイムチェックを行わない設定をします。
656         * タグに独自属性としてrealTimeChk="xxx"を追記します。
657         * falseを設定した場合にチェックが行われなくなります。
658         * 初期値はリアルタイムチェックを行う(何も指定しない)です。
659         * 
660         * この属性は、optionAttributesへの設定と同様の動作を行います。
661         *
662         * @og.rev 5.9.32.2 (2018/05/18) 新規追加
663         *
664         * @param   flg リアルタイムチェックを行うかどうか
665         */
666        public void setUseRealTimeCheck( final String flg ) {
667                String rtcf = getRequestParameter( flg );
668                // optionAttributes扱いで登録します。
669                if( rtcf != null && rtcf.length() > 0 ){
670                        add( "optionAttributes", " realTimeChk=\""+getRequestParameter( flg )+"\"" );
671                }
672        }
673
674        /**
675         * このオブジェクトの文字列表現を返します。
676         * 基本的にデバッグ目的に使用します。
677         *
678         * @return このクラスの文字列表現
679         */
680        @Override
681        public String toString() {
682                return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
683                                .println( "VERSION"                                     ,VERSION                        )
684                                .println( "td_flag"                                     ,td_flag                        )
685                                .println( "colspan"                                     ,colspan                        )
686                                .println( "nextForm"                            ,nextForm                       )
687                                .println( "CHECK_TYPE"                          ,CHECK_TYPE                     )
688                                .println( "HTML_LABEL_SEPARATOR"        ,CLM                            )
689                                .println( "HTML_COLUMNS_MAXSIZE"        ,COLUMNS_MAXSIZE        )
690                                .println( "Other..."                            ,getAttributes().getAttribute() )
691                                .fixForm().toString() ;
692        }
693}