h:commandButton不能将参数提交到备用Bean [英] h:commandButton can NOT submit parameters to backing bean
问题描述
我想向我的后备bean提交键值,以便我知道集合用户中的哪个人试图更新.我认为我需要使用f:param来执行此操作,但是以某种方式它不起作用.如果我使用af:commandButton而不是h:commandButton,它将提交的值很好.
I would like to submit a key value to my backing bean so that I know which person within a collection user trying to update. I think I need to used f:param to do so, but somehow it does not work. It will submit the value just fine if I use af:commandButton instead of 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>
这就是我试图将提交的值显示出来的方法.
and here is how I am trying to get my submitted values out.
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String edi_tmp = (String)map.get("selectedEDI");
但是我收到了ArrayIndexOutOfBound异常,请帮忙,谢谢.
But I got the ArrayIndexOutOfBound Exception, please help, thanks.
推荐答案
如果按钮位于<h:dataTable>
或任何其他 UIData#getRowData()
或
If the button is inside a <h:dataTable>
or any other UIData
component, then you should be retrieving the "current" row object by UIData#getRowData()
or DataModel#getRowData()
. No need to pass the row identifier around as parameter or so.
例如
@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>
保持简单.
这篇关于h:commandButton不能将参数提交到备用Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!