2

バッキング Bean にキー値を送信して、コレクション ユーザー内の誰が更新しようとしているかを把握したいと考えています。そのためには f:param を使用する必要があると思いますが、どういうわけか機能しません。h:commandButton の代わりに af:commandButton を使用すると、問題なく値が送信されます。

これが私のボタンです:

<h:commandButton styleClass="cntctmBtn" value="Update" action="#{pullForm.updateDependent}">
   <f:param name="selectedIndex" value="#{loop.index}" />
   <f:param name="selectedEDI" value="#{eachOne.identifier.dodEdiPnId}" />
</h:commandButton>

これが、送信された値を取得しようとしている方法です。

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String edi_tmp = (String)map.get("selectedEDI");

しかし、ArrayIndexOutOfBound 例外が発生しました。助けてください、ありがとう。

4

1 に答える 1

3

ボタンが<h:dataTable>またはその他のコンポーネント内にある場合、またはUIDataによって「現在の」行オブジェクトを取得する必要があります。行識別子をパラメーターなどとして渡す必要はありません。UIData#getRowData()DataModel#getRowData()

例えば

@ManagedBean
@ViewScoped
public class Bean {
    private List<Person> persons;
    private DataModel<Person> personModel;

    public Bean() {
        persons = loadItSomehow();
        personModel = new ListDataModel<Person>(persons);
    }

    public void update() {
        Person selectedPerson = personModel.getRowData(); // There it is.
        // ...
    }

    // Add/generate getters/setters/etc.
}

<h:form>
    <h:dataTable value="#{bean.personModel}" var="person">
        <h:column>
            <h:commandButton value="update" action="#{bean.update}" />
        </h:column>
    </h:dataTable>
</h:form>

複雑にしないでおく。

以下も参照してください。

于 2010-09-14T17:33:29.523 に答える