1
votes

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

}
1
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
There are no js errors in the browser console. - Catfish
What is the scope of your backing bean? - partlov
Can't answer from top of head as I've never used it, but Googling "rich:columns sortby" gives me among others this possible duplicate question and this and this thread on community.jboss.org. Have you been through it? - BalusC
I've tried all of those links a few times already. - Catfish

1 Answers

1
votes

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