2 * Copyright (c) 2009 The openGion Project.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.opengion.plugin.column;
18 // import org.opengion.hayabusa.common.HybsSystem; // 8.0.0.0 (2021/07/31) Delete
19 import org.opengion.hayabusa.db.AbstractRenderer;
20 import org.opengion.hayabusa.db.CellRenderer;
21 import org.opengion.hayabusa.db.DBColumn;
22 import org.opengion.fukurou.util.StringFormat;
23 import org.opengion.fukurou.util.StringUtil;
24 import org.opengion.fukurou.util.TagBuffer;
27 * URLCALL レンデラーは、汎用ボタンにURLをクリックする機能を適用するクラスです。
29 * ボタンのラベルは、ラベルリソースから取得します。それ以外に値に設定された文字列から、
30 * 変数 $1,$2,$3,$4 を適用できます。
31 * AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てます。
33 * <button name="CC" id="CC" type="button" onClick="window.open('URL','CC_FRM').close();" >CC</button>
34 * <iframe style="display:none;" name="CC_FRM"><!-- --></iframe>
36 * window.open で、すぐに閉じるのと、iframe を 見えなくすることで、ajax と同じような感じで実行できる。
38 * ※ 色々と試行錯誤した結果、window.open + 見えない iframe 方式で行います。
41 * <button name="AA" id="AA" type="button" onClick="ajaxCall('URL');" >ラベルAA</button>
42 * default.js に ajaxCall を用意して、非同期にURLを呼び出す。
43 * IE11 では、localhost 等から呼び出せない(セキュリティ)を低にすれば動作する。Microsoft Edge では実行可能。
44 * 将来的には、こちらの方法になる可能性は大きい
46 * 不採用案2:location.href 遷移
47 * <button name="BB" id="BB" type="button" onClick="location.href='URL'" >ラベルBB</button>
48 * どうしても、URLに飛んで画面遷移してしまう。return false; を入れてもすでに遷移してしまう。
50 * @og.rev 7.4.2.0 (2021/05/14) 新規作成
54 * @author Kazuhiko Hasegawa
57 public class Renderer_URLCALL extends AbstractRenderer {
58 /** このプログラムのVERSION文字列を設定します。 {@value} */
59 private static final String VERSION = "8.5.2.0 (2023/07/14)" ;
61 // private static final CellRenderer DB_CELL = new Renderer_URLCALL() ;
69 * このコンストラクターで、基本オブジェクトを作成します。
72 public Renderer_URLCALL() {
77 * DBColumnオブジェクトを指定したprivateコンストラクター。
79 * @param clm DBColumnオブジェクト
81 private Renderer_URLCALL( final DBColumn clm ) {
85 label = clm.getLabel();
86 param = StringUtil.nvalAdd( clm.getRendererParam() ,
87 clm.getRendererAttributes().get( "optionAttributes" ) );
91 * 各オブジェクトから自分のインスタンスを返します。
92 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
95 * @param clm DBColumnオブジェクト
96 * @return CellRendererオブジェクト
99 public CellRenderer newInstance( final DBColumn clm ) {
100 return new Renderer_URLCALL( clm );
106 * @og.rev 7.4.2.0 (2021/05/14) 新規作成
109 * @return データの表示用文字列
113 public String getValue( final String value ) {
114 return makeButton( name, value );
119 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない
121 * 基本は、#getValue( String ) をそのまま返します。
123 * @og.rev 7.4.2.0 (2021/05/14) 新規作成
127 * @return データ出力用の文字列
129 * @see #getValue( String )
132 public String getWriteValue( final String value ) {
133 return value == null ? "" : value;
139 * @og.rev 7.4.2.0 (2021/05/14) 新規作成
140 * @og.rev 8.5.2.0 (2023/07/14) iframeのnameに "_FRM" 追加
143 * @param value 入力値 表示するファイルのアドレス
144 * @return データ表示用の文字列
147 private String makeButton( final String name,final String value ) {
148 final String newVal = new StringFormat( param, value, name ).format(); // $C は name に置き換える。
150 final String button = new TagBuffer( "button" )
151 .add( "name" , name )
153 .add( "type" , "button" )
154 .add( "onClick" , "window.open('" + newVal + "','" + name + "_FRM').close();" )
155 .addBody( label ) // ボタンの表示
158 final String iframe = new TagBuffer( "iframe" )
159 // .add( "name" , name )
160 .add( "name" , name + "_FRM" ) // 8.5.2.0 (2023/07/14) Modify
161 .add( "style" , "display:none;" )
164 return button + iframe;