[EMAIL PROTECTED] wrote:
I just started working with myFaces (and tomahawk) for the past couple
of days and so I apologize if this question is really basic.
Here's what I have:
A (Shale) backing bean called "worklist" with:
private DataModel assignmentsModel = new ListDataModel();
..etc..
private List _assignments;
..etc..
public String getWorkList() {
//do some work to populate_assignments ..then..
assignmentsModel.setWrappedData(_assignments);
}
finally,
public DataModel getAssignments() {
return assignmentsModel;
}
I display my worklist in worklist.jsp and everything works great.
Now I want to introduce sorting into my table and therefore looked into
<t:commandSortHeader working within a <t:dataTable. I think I'm
supposed to have something like this in my worklist.jsp:
<t:dataTable id="items" value="#{worklist.assignments}"
var="assignment" sortColumn="#{worklist.sort}"
sortAscending="#{worklist.ascending}"
preserveDataModel="true"
preserveSort="true">
<h:column>
<f:facet name="header">
<t:commandSortHeader columnName="name"
arrow="true">
<h:outputText value="Assignment" />
</t:commandSortHeader>
</f:facet>
etc..
So I added methods getSort(), isAscending(), sort (final String column,
final boolean ascending) etc. to my worklist backingbean (using sample
code from MyFaces' "listexample" as a guide). My worklist.jsp page does
display with the little arrow but clicking on it returns me to the same
page (though the arrow faces the opposite way upon click - yeah!!),
however, no sorting happens, which is no major surprise since my bean's
sorting method isn't even hit..(:(
So my questions are:
0. Is my approach all wrong and should Ibe doing everything differently?
1. Does anybody see what i'm doing wrong?
2. Where should I add breakpoints to see what I'm messing up? (My code
doesn't even hit the sort method in my backing bean.)
The "sortColumn" attribute should point to a backing bean property that
is of type String. That property gets set (ie its setter gets called)
with the columnName value of whatever column the user chose to sort on.
The "sortAscending" attribute should point to a backing bean property
that is of type boolean. That property gets set to true/false when the
user clicks repeatedly on the same column header (ie sorts
asc/desc/asc/desc).
Your worklist.assignments method (ie the one referred to by the table's
"value" attribute) is then required to look at the backing bean's
properties that are the target of sortColumn and sortAscending and
return its list in the order specified by those (String, boolean)
properties.
I hope that's the info you were looking for.
Regards,
Simon