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のdataTableで選択行のデータを取得

Last updated at Posted at 2019-03-29

JSFのdataTableで作成した一覧から選択行のデータを取得する方法をメモ。
ほとんどおまじないみたいなものですが……。

TestCBb
// 選択行データ取得
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext exContext = context.getExternalContext();

@SuppressWarnings("rawtypes")
Map map = exContext.getRequestMap();
SelectDataInfo selectData = (SelectDataInfo)map.get("m");

すこしだけxhtmlの内容にかかっているので、
xhtmlの内容も追記しておきます。

xhtml
<h:dataTable value="#{TestCBb.pageData}" var="m" styleClass="list">
  <h:column headerClass="header">
    <f:facet name="header">見出し1</f:facet>
    <h:outputText value="#{m.value1}" />
  </h:column>
  <h:column headerClass="header">
    <f:facet name="header">見出し2</f:facet>
    <h:outputText value="#{m.value2}" />
  </h:column>
  <h:column headerClass="header">
    <f:facet name="header">見出し3</f:facet>
    <h:outputText value="#{m.value3}" />
  </h:column>
</h:dataTable>

もちろんTestCBb.pageDataの型はSelectDataInfoをListにしたものです。
要するに、
 SelectDataInfo selectData = (SelectDataInfo)map.get("m");
のmはdataTableで設定した名前を持ってきているというだけなんですが……。
すぐ忘れそうなのでメモ。

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?