UIマップの一意の要素IDの確認

JavaScriptコードを変更し、UIマップについて一意の要素IDが正しくレンダリングされていることを確認する方法を説明します。

変更が必要になるのは、getElementById() (または類似する)関数を使用してリストIDを生成し、アカウント検証や関連するエラーを回避するために、HTMLをレンダリングするコードの場合のみです。

次のサンプル・スニペットには、必要な変更が含まれています。


...
function getElementsFromList(namePrefix) {
    var ret = [];
    var elements = document.getElementsByTagName("INPUT");
    for(var i=0;i<elements.length;i++) {
        var elemID = elements[i].id;
        if((id) && (id.startsWith(namePrefix + '_')) {
            ret.push(elements[i]);
        }
    }
...
return ret;

生成されたUIマップのIDは必ずしも一意でないため、前述のコードでは、レンダリングされたHTMLでフレームワークが正しく処理を行うために、アンダースコアと行番号を追加して(例: myField_​1、myField_​2)実行時に一意性が確認され、生成されたUIマップに含まれる未変更のIDも参照できます。

また、spl.propertiesファイル内のスイッチを使用すると、グリッド内で要素に対して一意のIDの生成を無効にできますが(後述の説明を参照)、標準準拠の理由から、このスイッチはデフォルト値のままにすることをお薦めします。

 
Property Name: spl.runtime.compatibility.uiMapDisableGenerateUniqueHtmlIDs
File Name: spl.properties (under web project in FW)
Default Value: false
Accepted Values: true or false
Description: This property controls the generation of unique IDs for all input elements inside 
a list. When this value is set to true it disables the generation of unique IDs, thus 
replicating the old behavior. When this property is set to false or this property is missing 
it enables the generation of unique IDs, thus enabling the list to be standards-compliant.