【问题标题】:h:commandButton can NOT submit parameters to backing beanh:commandButton 不能向支持 bean 提交参数
【发布时间】:2010-09-14 17:26:33
【问题描述】:

我想向我的支持 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 异常,请帮忙,谢谢。

【问题讨论】:

    标签: jsf jsf-2 oracle-adf


    【解决方案1】:

    如果按钮位于&lt;h:dataTable&gt; 或任何其他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>
    

    保持简单。

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-28
      • 1970-01-01
      相关资源
      最近更新 更多