-
1. Re: How to attach actionListner to rich: column header
tiwari.vikash Jul 9, 2012 4:11 PM (in response to tiwari.vikash)I removed sortby attribute and implemented custom sorting.
<f:facet name="header">
<a4j:commandLink id="idHeader" actionListener="#{officeTableBean.sort}" reRender="userTable">
<h:outputText value="ID" />
<h:panelGroup layout="block" styleClass="#{officeTableBean.columnOrderingMap['id']}"/>
<f:attribute name="sortField" value="id" />
</a4j:commandLink>
</f:facet>
I am using reflection to get data model of data table. is there a better way?
/**
* Method to get data model of HtmlDataTable using reflection.
*
* @param dataTable
* @return DataModel
*/
@SuppressWarnings("unchecked")
private <T> List<T> retrieveRecordList(HtmlDataTable dataTable){
List<T> recordList = Collections.emptyList();
try{
Method method = dataTable.getClass().getSuperclass().getSuperclass().getDeclaredMethod("getDataModel");
method.setAccessible(true);
DataModel dataModel = (DataModel) method.invoke(dataTable);
recordList = (List<T>) dataModel.getWrappedData();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return recordList;
}