0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSFでコンボボックスを作る

Posted at

JSFで画面を製造していてコンボボックスが必要になったのですが、JSFにはコンボボックスがない。
ということで力技で作ってもらったので、方法をメモ。

xhtml
<h:inputText value="#{m.name}" maxlength="25" />
<datalist>
  <ui:repeat value="#{m.nameList}" var="item">
    <option value="#{item.getLabel()}" />
  </ui:repeat>
</datalist>

inputTextの直後にdatalistを設定します。
本当はここで要素にidとlistを追加できれば楽なのですが、できないのでjs側で無理矢理埋め込みます。

js
$("datalist").each(function(i) {
  var keywords = "keywords" + i;
  $(this).attr("id", keywords);
  $(this).prev("input").attr("list", keywords);
});

ここで、datalistの要素にid、
inputTextの要素にlist(ここでは直前のinputに要素を追加するよう指定している)を追加しています。
keywordはただの名前なので、あまり気にしなくて大丈夫です。
inputTextとdatalistを紐付けるためのものらしい。jsはわたしも詳しくないのですが……。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?