legacy-knowledge-base
公開されました Sep. 10, 2025

instance-id'フィールドとは何ですか?

written-by

Jose L. Bango

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • instace-idまたはinstanceIdフィールドとは何ですか?

環境

  • すべてのLiferayバージョン

解像度

  • ランダムな英数字だ。
  • Liferayはこの値を使ってフィールドを一意に識別できるようにします。
  • 実際の生成サンプルコード:
    • JS(fieldSupport.js)
      export function generateInstanceId(isNumbersOnly) {
      return Math.random()
      .toString(isNumbersOnly ? 10 : 36)
      .substr(2, 8);
      }
    • Java(StringUtil.randomString()メソッドを使用)
      public static String randomString(int length) {
      Random random = new Random();

      char[] chars = new char[length];

      for (int i = 0; i < length; i++) {
      int index = random.nextInt(_RANDOM_STRING_CHAR_TABLE.length);

      chars[i] = _RANDOM_STRING_CHAR_TABLE[index];
      }

      return new String(chars);
      }

追加情報

  • フィールドIDの生成に使われることもあるが、これも一意でなければならない。 W3C DOM#getElementById()に従います。
    • 複数の要素がその値を持つID属性を持つ場合、返される値は未定義です。
did-this-article-resolve-your-issue

legacy-knowledge-base