0

I'm trying to get a jsf 1.2 legacy project working using Richfaces 3.3.Final.

I'm trying to create a datatable with dynamic columns and i am getting the error:

Caused by: javax.el.PropertyNotFoundException: /index.xhtml @44,58 value="#{results[ind].columnName}": Property '0' not found on type ..../TableBean

I'm basically following the example from this page - http://livedemo.exadel.com/richfaces-demo/richfaces/columns.jsf?tab=usage&cid=278645 but they don't show their backing bean code.

Here's my relevant code

<rich:dataTable id="resultsTable" value="#{tableBacking.results}" var="results">
    <f:facet name="header">
        <h:outputText value="Results" />
    </f:facet>
    <rich:column>
        <f:facet name="header">
            <h:outputText value="First Columns" />
        </f:facet>
    </rich:column>
    <rich:columns value="#{tableBacking.columns}" var="columns" index="ind" id="column#{ind}">
        <f:facet name="header">
            <h:outputText value="#{columns.header}" />
        </f:facet>

        <h:outputText value="#{results[ind].columnName}" />

    </rich:columns>
 </rich:dataTable>

Backing bean

public class TableLookupBacking {

    private List<ColumnModel> columns = null;
    private List<TableBean> results = null;

        public List<ColumnModel> getColumns() {

        if(columns == null) {
            columns = new ArrayList<ColumnModel>();
            columns.add(new ColumnModel("header", "Property"));
            columns.add(new ColumnModel("header2", "Property"));
            columns.add(new ColumnModel("header3", "Property"));
            System.out.println("columns.size = "+columns.size());
        }
        return columns;
    }

        public List<TableBean> getResults() {

        if(results == null) {
            results = new ArrayList<TableBean>();
            results.add(new TableBean("id"));
            results.add(new TableBean("name"));
            System.out.println("results.size = "+results.size());
            System.out.println("results.0 = "+results.get(0).getColumnName());
        }
        return results;
    }

        public void setResults(ArrayList<TableBean> results) {
        this.results = results;
    }
        public void setColumns(ArrayList<ColumnModel> columns) {
        this.columns = columns;
    }
}

TableBean

public class TableBean {

    private String columnName;

    public TableBean(String columnName) {
        this.columnName = columnName;
    }
    public String getColumnName() {
        return columnName;
    }
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }
}
Catfish
  • 18,876
  • 54
  • 209
  • 353

2 Answers2

0

Change the line

<h:outputText value="#{results[ind].columnName}" />

to

<h:outputText value="#{results.columnName}" />
prageeth
  • 7,159
  • 7
  • 44
  • 72
  • The only problem with this is it's printing the data backwards. It prints it in columns rather than rows. – Catfish Dec 19 '12 at 19:02
0

I finally figured out that you need to have a list of lists for the richfaces datatable. This is not how it's done using primefaces, which i'm used to using. For the record, there is basically ZERO examples of the backing bean code for the richfaces examples which is just another reason why primefaces is that much better.

private List<List<TableBean>> results = null;

public List<List<TableBean>> getResults() {

    if(results == null) {
        results = new ArrayList<List<TableBean>>();
        results.add(new TableBean("id"));
        results.add(new TableBean("name"));
        System.out.println("results.size = "+results.size());
        System.out.println("results.0 = "+results.get(0).getColumnName());
    }
    return results;
}
Catfish
  • 18,876
  • 54
  • 209
  • 353