I faced problem with disabling RichFaces sorting by column on button click. Maybe someone can help
I have AlertsList datatable:
<rich:extendedDataTable id="#{module}AlertsList"
tableState="#{alertsController.dataModel.tableState}"
enableContextMenu="false"
height="220px"
sortMode="single"
value="#{alertsController.dataModel}"
var="alert" width="100%"
selection="#{alertsController.selection}"
reRender="#{module}AlertsListDatascroller"
rows="#{alertsController.dataModel.rowsPerPage}"
binding="#{alertsController.dataModel.extandetDataTable}"
rowClasses="evenRow,oddRow">
......
<rich:column sortBy="#{alert.lockedByUsername}" width="7%"
style="#{(not empty alert.first4OfLockedByUsername and (alertsController.dataModel.selectedItem != alert)) ? 'background-color: darkgray' : ((alert.action != null and alert.action.classificationTypeEntity.classificationType eq 'POSTPONED') ? 'background-color: thistle' : '')}"
label="#{message['alertsnalysis.alertList.table.lock']}"
selfSorted="#{currentUser.authorities['SVWI_MODIFICATION']}"
id="#{module}AL_lockedByUsername">
<f:facet name="header">#{message['alertsnalysis.alertList.table.lock']}</f:facet>
<h:outputText value="#{alert.first4OfLockedByUsername}" />
</rich:column>
......
<rich:column sortBy="#{alert.id}" width="5%"
style="#{(not empty alert.first4OfLockedByUsername and (alertsController.dataModel.selectedItem != alert)) ? 'background-color: darkgray' : ((alert.action != null and alert.action.classificationTypeEntity.classificationType eq 'POSTPONED') ? 'background-color: thistle' : '')}"
label="#{message['alertsnalysis.alertList.table.id']}"
selfSorted="#{currentUser.authorities['SVWI_MODIFICATION']}"
id="#{module}AL_id">
<f:facet name="header">#{message['alertsnalysis.alertList.table.id']}</f:facet>
<h:outputText value="#{alert.id}" />
</rich:column>
....
<rich:datascroller id="#{module}AlertsListDatascroller" for="#{module}AlertsList" ajaxSingle="false" page="#{alertsController.dataModel.currentPage}"></rich:datascroller>
So I added button to change soring table results by 3 columns at a time, cause due my current realisation i cant sorting data by clicking on different column headers(way with sortMode="multiply" is not accepted):
<h:form id="buttonReset">
<h:panelGrid columns="2">
<a4j:commandButton id="resetSortingButton" styleClass="FatButtonStyle" reRender="#{module}AlertsList"
action="#{alertsController.dataModel.defaultSortField}" value="Default Sorting"/>
</h:panelGrid>
</h:form>
Also I have implementaion of Modifiable:
public abstract class TableDataModel<T, U> extends SerializableDataModel implements Modifiable, Serializable {
...
protected String sortField = null;
..
public void defaultSortField(){ // call on button "Default Sorting" click action
this.sortField = "default"; //set field to default
this.detached = false;
this.defaultFlag = true;
this.i = 0;
}
...
@Override
public void walk(final FacesContext context, final DataVisitor visitor, final Range range, final Object argument)
throws IOException {
final int firstRow = ((SequenceRange) range).getFirstRow();
final int numberOfRows = ((SequenceRange) range).getRows();
if (detached) {
for (final U key : wrappedKeys) {
setRowKey(key);
visitor.process(context, key, argument);
}
} else {
List<T> list = Collections.<T>emptyList();
if (rangeChanged((SequenceRange) range) || sortChanged(sortField) || filterMapChanged(filterMap) || descChanged(descending) || ((MethodReRendering) this).getReRenderingEnabled()) {
lastRange = (SequenceRange) range;
lastSortField = sortField;
lastFilterMap = new HashMap<String, Object>(filterMap);
lastDescending = descending;
((MethodReRendering) this).setReRenderingEnabled(false);
list = findObjects(firstRow, numberOfRows, sortField, filterMap, descending); //in findObjects() checking if sortField == "default", then sorting by 3 columns, else by column in field value
wrappedKeys = new CopyOnWriteArrayList<U>();
for (final T object : list) {
wrappedKeys.add(getId(object));
wrappedData.put(getId(object), object);
visitor.process(context, getId(object), argument);
}
} else {
for (U id :wrappedKeys)
visitor.process(context, id, argument);
}
}
}
...
public void modify(List<FilterField> filterFields, List<SortField2> sortFields) {
filterMap.clear();
SortField2 sortField2 = null;
String expressionStr = null;
ExtendedFilterField extendedFilterField = null;
String value = null;
Expression expression = null;
if (sortFields != null && !sortFields.isEmpty()) {
sortField2 = sortFields.get(0);
expression = sortField2.getExpression();
......
}
...
}
So problem is when I click my btn I change sortField value and walk() method returns new sorted by 3 columns data to my table ( see findObjects(firstRow, numberOfRows, sortField, filterMap, descending);). All works fine.
But on my page I still can see (by icon or if i refresh my page it calls modify() method with List sortFields parameter == "alertId") that means what data still sorted by alertId column, but new sorting implemented. What logic I need add to my defaultSortField() method (calls on "Default Sorting" button click), for disable sorting by alertId column?
UPDATE1: Added binding my extendedDataTable to property: But maybe someone know how can I disable current sorting? UIExtendedDataTable extandetDataTable = null;
public void setExtandetDataTable(UIExtendedDataTable extandetDataTable) {
this.extandetDataTable = extandetDataTable;
List<SortField2> sortField2s = extandetDataTable.getSortFields();
SortField2 sortField2;
}
public UIExtendedDataTable getExtandetDataTable() {
return extandetDataTable;
}