ページの先頭行へ戻る
 Apcoordinatorユーザーズガイド

16.4.6 外付け属性の利用

外付け属性対応のUJIタグ一覧”に示したコンポーネントタグでは、入力項目のデータを、String等の一般的な型のプロパティで受け取ることができます。この場合、入力項目の色、大きさなどの属性は、外付け属性を使って指定できます。

外付け属性の利用手順

外付け属性を利用する場合は、DataBeanの代わりに、com.fujitsu.uji.AttributeDataBeanを利用します。

package sample;

public class BodyBean extends com.fujitsu.uji.AttributeDataBean
{
    protected String strData;

    public String getStrData() {
        return strData;
    }

    public void setStrData(String value) {
        strData = value;
    }
}

属性は、AttributeDataBeanクラスのsetAttributeメソッドで指定します。引数は、プロパティ名、属性名、属性の値となります。

dataBean.setAttribute("strData", TagAttributeNames.FOREGROUND, "red");

属性の指定方法は項目クラスや、タグのアトリビュートでの指定と共通です。uji:fieldStringタグの場合は、FieldStringクラスやFieldStringModelインタフェースと共通になります。項目クラスのインタフェースで、getメソッド、isメソッドに対応する属性が指定可能です。com.fujitsu.uji.compo.TagAttributeNamesクラスは、属性名の定数を持っています。

ポイント

例では、AttributeDataBeanクラスを利用していますが、データBeanにcom.fujitsu.uji.BeanAttributeAccessインタフェースを実装すれば、任意のクラスで利用可能です。

外付け属性での選択肢の指定

選択肢を表すタグ、uji:comboBox、uji:listBox、uji:buttonListについても、外付け属性を利用することができます。
データBeanには、選択情報を保存するプロパティを作成します。プロパティの型はString (複数選択の場合はString[])を使用します。フォームが送信されると、選択された選択肢の値がこのプロパティに代入されます。以下は、データBeanの作成例です。

package sample;
import com.fujitsu.uji.compo.*;

public class BodyBean extends com.fujitsu.uji.AttributeDataBean
{
    protected String comboData;

    public String getComboData() {
        return comboData;
    }

    public void setComboData(String value) {
        comboData = value;
    }
}

選択肢については、特別な属性名valuesにjava.util.Map型で設定します。このMapは、選択肢の値をキーに、表示文字列を値に持ったものです。選択肢の順序を一定にするため、com.fujitsu.uji.util.SequencedMapが利用できます。
また、選択肢の色などのインデックスが必要な属性は、文字列の配列として指定します。

import java.util.*;
import com.fujitsu.uji.util.*;
import com.fujitsu.uji.compo.*;
    
    ....
    // 値
    dataBean.setComboData("HND");
    // 選択肢
    Map map = new SequencedMap();
    map.put("HND", "羽田");
    map.put("NRT", "成田");
    dataBean.setAttribute("comboData", TagAttributeNames.VALUES, map);
    // 選択肢の色
    String[] colors = new String[]{"blue","green"};
    dataBean.setAttribute("comboData", TagAttributeNames.COLORAT, colors);

リストとテーブルの利用

AttributeDataBeanを利用する場合は、uji:listおよびuji:tableについても、com.fujitsu.uji.model.list.ListModelやcom.fujitsu.uji.model.TableModelの代わりに、配列を利用することができます。この時、属性名elementClass(uji:listの場合)、rowClassとcolumnClass(uji:tableの場合)を同様に利用可能です。

uji:listおよびuji:tableの属性名は、それぞれListModelインタフェースおよびTableModelインタフェースで定数として定義されています。

外付け属性対応のUJIタグ一覧

タグ名

関連する項目クラス、
インタフェース

値の型

利用可能な属性名(*1)

uji:fieldString

FieldString
FieldStringModel

String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、editable、enabled、plain、visible、infoText、maxByteLength、maxLength、fullField、indispensableField、enableChars、enableCharType、uppercase

uji:fieldEJString

FieldString
FieldStringModel

String

background、fontSize、foreground、enabled、plain、visible、maxLength

uji:fieldLong

FieldLong
FieldLongModel2

long
String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、editable、enabled、plain、visible、infoText、maxByteLength、maxLength、fullField、indispensableField、enableChars、maximumValue、minimumValue

uji:fieldBigInteger

FieldBigInteger
FieldBigIntegerModel2

BigInteger
String

uji:fieldDouble

FieldDouble
FieldDoubleModel2

double
String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、editable、enabled、plain、visible、infoText、maxByteLength、maxLength、fullField、indispensableField、enableChars、maximumValue、minimumValue、maxDecimalDigit、maxIntegerDigit

uji:fieldBigDecimal

FieldDecimal
FieldDecimalModel2

BigDecimal
String

uji:fieldDate

FieldDate
FieldDateModel2

Date
String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、editable、enabled、plain、visible、infoText、maxByteLength、maxLength、fullField、indispensableField、enableChars、locale(java.util.Locale)、timeZone(java.util.TimeZone)

uji:fieldTextArea

FieldTextArea
FieldTextAreaModel2

String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、editable、enabled、visible、infoText、maxByteLength、maxLength、indispensableField

uji:checkbox

CheckBox
CheckBoxModel

String

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、enabled、visible、label

uji:pushbutton

PushButton
PushButtonModelValued
PushButtonValued
PushButtonModel

任意 (*3)

uji:radioButton

RadioButton
RadioButtonModel

任意 (*4)

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、tipText、enabled、visible、label

uji:anchor

Anchor
AnchorModel

任意 (*3)

background、fontSize、fontStyle、fontWeight、foreground、textDecoration、visible、label

uji:comboBox

ComboBox
ComboBoxModel2

String

values(Map)、colorAt(String[])、enabled、visible

uji:listBox

ListBox
ListBoxModel2

String
String[](*2)

values(Map)、colorAt(String[])、enabled、visible、multipleMode

uji:buttonList

ButtonList
ButtonListModel2

String
String[](*2)

values(Map)、colorAt(String[])、enabled、visible、multipleMode

uji:list

DefaultListModel
ListModel

Object[]

elementClass(String[])

uji:table

DefaultTableModel

TableModel

Object[][]

rowClass(String[])、columnClass(String[][])

(*1)「属性名(属性値の型)」の形式で記載しています。属性値の型が記載されていない属性はString型で設定します。この場合、数値やboolean値を設定するものについては、java.lang.Integer型、java.lang.Boolean型などを利用することも可能で、toStringメソッドで取得できる値が利用されます。
com.fujitsu.uji.compo.TagAttributeNamesクラス等で持つ属性名の定数を利用する場合は、全て大文字で記述します。

    例) "colorAt" → com.fujitsu.uji.compo.TagAttributeNames.COLORAT 

(*2) multipleModeがtrueの場合にはString[]で指定します。

(*3) selectedPropertyアトリビュートを省略した場合、ボタンの値やアンカーの値は不要であるため、プロパティをデータBeanに作成する必要はありません。

(*4) pickUpModeアトリビュートにlistまたはtableを指定した場合、ラジオボタンに対応付けるオブジェクトは不要であるため、プロパティをデータBeanに作成する必要はありません。