1

I've been googling this for 2 days now and trying various attempts that i've seen posted on the web, but nothing seems to be working for me.

I'm trying to get a richfaces 3 datatable to have sorted columns and when i click the column header, nothing actually gets sorted.

Anyone have any idea what i'm missing? Do i need to implement an attribute on my backing bean or something?

<rich:extendedDataTable id="resultsTable" value="#{tableBacking.results}" var="results" rowKeyVar="row">
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Row Number" />
            </f:facet>                  
        </rich:column>

        <rich:columns value="#{tableBacking.columns == null ? '' : tableBacking.columns}" 
            var="columns" index="ind" id="column#{ind}" 
            sortBy="#{results[ind].data}" rendered="#{tableBacking.columns != null}">
            <f:facet name="header">
                <h:outputText value="#{columns.columnDescription}" />
            </f:facet>

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

        </rich:columns>
    </rich:extendedDataTable>

TableLookupBacking bean

public class TableLookupBacking{
    private List<List<TableData>> results = null;
    private List<TableData> columns = new ArrayList<TableData>();

    public void search() {
        getData("");
    }

    private void getData(String whereClause) {

        try {
            DataDao dd = new DataDao();
            results = dd.getData(WebDataViewerConstants.SCHEMA_NAME, selectedTable, whereClause);
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Unable to retrieve data with selected search criteria in getData."));
        }
    }
// columns get set in another method that is triggered off something else the user does    

// Getters and Setters

}
Catfish
  • 18,876
  • 54
  • 209
  • 353
  • You might need to look in your browser's Javascript console to look out for possible javascript errors and make sure that JSF is not silently returning a conversion or validation error in the network level response – kolossus Jan 04 '13 at 00:52
  • There are no js errors in the browser console. – Catfish Jan 04 '13 at 04:54
  • What is the scope of your backing bean? – partlov Jan 04 '13 at 10:44
  • Can't answer from top of head as I've never used it, but Googling ["rich:columns sortby"](http://google.com/search?q=rich:columns+sortby) gives me among others [this possible duplicate question](http://stackoverflow.com/questions/1119321/richfaces-richcolumns-and-sorting) and [this](https://community.jboss.org/thread/15175) and [this](https://community.jboss.org/thread/16584) thread on community.jboss.org. Have you been through it? – BalusC Jan 07 '13 at 14:33
  • I've tried all of those links a few times already. – Catfish Jan 07 '13 at 14:40
  • Is your `rowKeyVar` attribute OK? Shouldn't be something like `#{results.row}`? – partlov Jan 13 '13 at 22:18
  • @Catfish: really? All those 3 links suggest among others to set `sortOrder`. Your current answer turns out that you actually didn't! – BalusC Jan 14 '13 at 14:34
  • I had sortOrder set to various different things in my rich:columns - none of which were correct apparently. I had not understood that i needed to create a `Map` and pass "columns" in my view. – Catfish Jan 14 '13 at 14:38

1 Answers1

1

I finally figured it out. All i needed to do was to add sortOrder="#{tableBacking.sortOrder[columns]}" to my rich:columns tag and then in my backer just add the following:

private Map<String, Object> sortOrder = new HashMap<String, Object>();

// setter and getter
Catfish
  • 18,876
  • 54
  • 209
  • 353