从rich:datatable绑定表获取行

时间:2012-01-25 09:09:33

标签: java jsf datatable richfaces

我正在使用java 6 jsf 1.2和richfaces 3.3.3 当我在Binded UIDataTable上调用函数getRowData

public void priorityChanged(ValueChangeEvent event) {
        Task currentTask = (Task) table.getRowData();

<h:selectOneMenu id="id182_#{rkv}" value="#{dataItem.priority}"
    valueChangeListener="#{customerAdminHandler.priorityChanged}"
    onchange="submit()">
    <f:selectItems value="#{customerAdminHandler.priorityTypes}" />
</h:selectOneMenu>

我在table.getRowData()上得到一个例外;

java.lang.IllegalArgumentException
    at javax.faces.model.ListDataModel.getRowData(ListDataModel.java:150)
    at org.ajax4jsf.model.SequenceDataModel.getRowData(SequenceDataModel.java:147)
    at org.ajax4jsf.component.UIDataAdaptorBase.getRowData(UIDataAdaptorBase.java:257)

2 个答案:

答案 0 :(得分:1)

我使用

绕过了这个问题
<f:setPropertyActionListener value="#{dataItem}"
                            target="#{customerProductsHandler.currentApp}" />

而不是绑定表。 相同的代码在干净的环境中为我工作,所以我猜有一些jar问题。

无论如何,为了将来参考,我发现以下信息对于使用绑定表很有用

Richfaces 3.3 uses:
org.richfaces.component.html.HtmlDataTable

Richfaces 4  uses:
org.richfaces.component.UIDataTable

jsf1.2  uses:
javax.faces.component.html.HtmlDataTable;

jsf 2  uses:
import javax.faces.model.DataModel;

答案 1 :(得分:0)

您是否已将rich:dataTable绑定到托管bean的组件属性?另外,属性的类型必须是org.richfaces.component.html.HtmlDataTable,至少这是我们选择一行数据表的方法(使用@BalusC here的示例代码)。

jsp代码:

<script type="text/javascript">
    function dataTableSelectOneRadio(radio) {
        var id = radio.name.substring(radio.name.lastIndexOf(':'));
        var el = radio.form.elements;
        for (var i = 0; i < el.length; i++) {
            if(el[i].name != undefined) {
                if (el[i].name.substring(el[i].name.lastIndexOf(':')) == id) {
                    el[i].checked = false;
                }
            }
        }
        radio.checked = true;
    }
</script>
<!-- some html/jsp code -->
<rich:dataTable id="dtDocCartera" style="width:100%"
    binding="#{busquedaDocCartera.hdtCredito}"
    value="#{busquedaDocCartera.lstCredito}" var="credito" rows="15">
    <rich:column>
        <f:facet name="header">
            <h:outputText value="Select" />
        </f:facet>
        <h:selectOneRadio onclick="dataTableSelectOneRadio(this)"
            valueChangeListener="#{busquedaDocCartera.setSelectedItem}">
            <f:selectItem itemValue="null"/>
        </h:selectOneRadio>
    </rich:column>
    <rich:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="Some Data" />
        </f:facet>
        <h:outputText value="#{credito.data}" />
    </rich:column>
</rich:dataTable>

这是我们的托管bean:

@KeepAlive(ajaxOnly=false)
public class PBusquedaDocCartera {
    private HtmlDataTable hdtCredito;
    private List<ECredito> lstCredito;
    //This will be the selected data
    private ECredito credito;
    //getters and setters for attributes...
    public void setSelectedItem(ValueChangeEvent event) {
        try {
            credito = (ECredito)hdtCredito.getRowData();
        } catch (Exception objEx) {
            //logging errors...
        }
    }
}