日期:2014-05-18  浏览次数:20796 次

JSF表格中如何获得用户的输入值
我要获得表格中所有选中行的某一列的所有值,请问怎么得到?

------解决方案--------------------
<t:updateActionListener value="#{}" property="#{myBean.selectRow}">
</t:updateActionListener>

value 为那一行对象, property是myBean 中的selectRow

这样就可以在bean中得到表现层
------解决方案--------------------
可以用js取到

------解决方案--------------------
刚刚没看清楚 如果要的得到某一列的值,提交后在bean中可以得到对象的list 你可以用装饰在对象中加上
boolean select 属性,然后在bean中遍历List.
比如: for(Object o : List)
{
//判断是不是选中的行对象
if(o.getSelect)
{
//具体得到
o.getter();
}
}
------解决方案--------------------
如果你是用dataTable来打印表格的话,下面是一个简单的例子 不过用的是myfaces的扩展table

<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="x"%>
<x:dataTable id="tableid" value="#{yourManagedBean.yourDataObjects}" var="yourDataObject" border="1" width="90%" preserveDataModel="true">

<x:column>
<f:facet name="header"><h:outputText value="Selected" /></f:facet>
<h:selectBooleanCheckbox value="#{yourDataObject.selected}"/>
</x:column>


</x:dataTable>

class YourDataObject {
private boolean selected = false;
//Implement the set,get/is method
}

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
public class YourManagedBean {
//Maybe you can use the ArrayList to store all YourDataObject instead of using DataModel. Please check.
private DataModel yourDataObjectDataModel;
//Before display the table, you can use yourDataObjectDataModel.setWrappedData(yourDataObjects)

  //After the command button is submit, you can use yourDataObjectDataModel.getWrappedData();
//And check the selected attribute of each YourDataObject.

}
------解决方案--------------------
学习。。。。