如何在与按钮相同的数据表行中获取输入组件的值? [英] How to get the value of an input component in the same datatable row as the button?

查看:95
本文介绍了如何在与按钮相同的数据表行中获取输入组件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,其中的行是动态的,每行都包含一个selectOneMenu.如果我在每行上都有一个按钮,并且想要在selectOneMenu上获取选定的项目,那么最好的方法是什么?

I have a datatable where the rows are dynamic and each row contain a selectOneMenu. If I have a button on each row and I want to get the selected item on the selectOneMenu, what's the best way to do it?

推荐答案

(本例中的Item只是代表每一行的javabean类,例如PersonProduct等)

(the Item in this example is just the javabean class representing every row, e.g. Person, Product, etc)

将其绑定到数据表的value.

<h:dataTable value="#{bean.model}" var="item">

如果下拉列表绑定到Item的属性,并且按钮绑定到同一bean的方法...

If the dropdown is bound to a property of Item and the button to a method of the same bean ...

<h:column>
    <h:selectOneMenu value="#{item.value}">
        <f:selectItems value="#{bean.values}" />
    </h:selectOneMenu>
</h:column>
<h:column>
    <h:commandButton value="submit" action="#{bean.submit}" />
</h:column>

...,那么您可以通过

... then you can grab the current item by DataModel#getRowData() and corrspondingly also the selected value in action method as follows:

public void submit() {
    Item item = model.getRowData();
    String value = item.getValue();
    // ...
}

这篇关于如何在与按钮相同的数据表行中获取输入组件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆