dov.amir
dov.amir

Reputation: 11637

get row from rich:datatable binding table

I am using java 6 jsf 1.2 and richfaces 3.3.3 When I call the function getRowData on the Binded UIDataTable

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

with

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

i get an exception on the 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)

Upvotes: 2

Views: 6226

Answers (2)

dov.amir
dov.amir

Reputation: 11637

I bypassed the problem by using

<f:setPropertyActionListener value="#{dataItem}"
                            target="#{customerProductsHandler.currentApp}" />

instead of a binding table. the same code worked for me on a clean environment so i guess there is some sort of jar problem.

anyway , for future reference I found the following information usefull for using a binding table

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;

Upvotes: 1

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

Have you binded your rich:dataTable to a component attribute of your managed bean? Plus, the type of the attribute must be org.richfaces.component.html.HtmlDataTable, at least this is how we achieved to select one row of the datatable (using the example code of @BalusC here).

The jsp code:

<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>

And this is our managed 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...
        }
    }
}

Upvotes: 0

Related Questions