2

我想向我的支持 bean 提交一个键值,以便我知道集合用户中的哪个人试图更新。我想我需要使用 f:param 来这样做,但不知何故它不起作用。如果我使用 af:commandButton 而不是 h: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

如果按钮位于 a<h:dataTable>或任何其他UIData组件内,那么您应该通过UIData#getRowData()or检索“当前”行对象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 回答