0

コンポーネントの変数リストに関連して JSF2.0 を使用する方法はありますか? たとえば、編集したい人物のリストがあるとします。それらは、個人データの変更を可能にするコンポーネント PersonEditor のリストとしてページに表示されます。各エディターは、単一の Person 要素に関連付けられています。これを機能させるには、次の手順を実行する必要があります

  1. 人のリストを取得する
  2. 人物ごとに PersonEditor を作成し、それを Person オブジェクトに関連付けます。
  3. 編集者のデータを入力します。

ユーザーのアクション:

  1. ユーザーが値を変更して [保存] を押すと、バッキング Bean によってデータが処理されます。

エディターに人のリストからのデータを入力するか、それをバッキング Bean にバインドできますが、同時にはできないため、行き詰まります。


people.xhtmlを試してみました

<ui:render value="#{bean.people}" var="person">
  <example:personEditor person="#{person}"/>
</ui:render>

personEditor.xhtml の場合:
a) person オブジェクトとの適切な関連付け、ただしバッキング Bean への接続なし

<h:form>
  <h:outputText value="#{cc.attr.person.name}"/>
  <h:commandButton name="Save" actionListener="editorBean.save">
    <f:ajax execute="@form" render="@form"/>
  </h:commandButton>
</h:form>

b) 人物オブジェクトとの関連付けはありませんが、バッキング Bean への接続があります - その人物をバッキング Bean に渡す方法はありません

<h:form>
  <h:outputText value="#{editorBean.name}"/>
  <h:commandButton name="Save" actionListener="editorBean.save">
    <f:ajax execute="@form" render="@form"/>
  </h:commandButton>
</h:form>

各エディターを個別のページに配置した場合、ユーザー ID を URL パラメーターとして (f:param または f:attribute を使用して) 渡し、それに応じて初期化することができます。この問題の解決策はありますか?

4

1 に答える 1

1

Hm, wondering why nobody answered this so far... Check this out:

http://balusc.blogspot.com/2006/06/communication-in-jsf.html

So your code would look something like this:

<h:form>
  <h:outputText value="#{cc.attr.person.name}"/>
  <h:commandButton name="Save" actionListener="#{editorBean.save}">
    <f:ajax execute="@form" render="@form"/>
    <f:setPropertyActionListener target="#{editorBean.editedPersonId}" value="#{cc.attr.person.id}" />
  </h:commandButton>
</h:form>

and upon calling editorBean.save the attribute will contain the id of the person edited (or you could pass the person object itself).

于 2010-07-31T08:27:41.860 に答える