protected void doDecode(FacesContext context, UIComponent component) {
super.doDecode(context, component);
composite.decode(context, component);
if (component instanceof UIExtendedDataTable) {
UIExtendedDataTable table = (UIExtendedDataTable) component;
Map<String, String> map = context.getExternalContext()
.getRequestParameterMap();
String clientId = component.getClientId(context);
if (SORT_FILTER_PARAMETER.equals(map.get(clientId))) {
String sortColumnId = map.get(SORT_FILTER_PARAMETER);
boolean isSingleSortMode = !"multi".equals(table.getSortMode());
boolean sorting = false;
boolean filtering = false;
boolean isGroupingOn = table.isGroupingOn();
boolean sortByGroupingColumn = false;
// String groupingColumnId = null;
UIColumn groupingColumn = null;
if (isGroupingOn) {
groupingColumn = table.getGroupByColumn();
sortByGroupingColumn = (groupingColumn == null ? false
: groupingColumn.getClientId(context).equals(
sortColumnId));
// groupingColumnId = table.getGroupingColumnId();
}
for (Iterator<UIColumn> columns = table.getChildColumns(); columns
.hasNext();) {
UIColumn column = columns.next();
String id = column.getId();
column.setId(id);
if (sortColumnId != null) {
sorting = true;
boolean isGroupingColumn = (isGroupingOn && column
.equals(groupingColumn));
if (sortColumnId.equals(column.getClientId(context))) {
// set sort order
if (map.containsKey(SORT_DIR_PARAMETER)) {
String sortDir = (String) map
.get(SORT_DIR_PARAMETER);
column
.setSortOrder((sortDir
.equals(SORT_DIR_PARAMETER_ASC) ? Ordering.ASCENDING
: (sortDir
.equals(SORT_DIR_PARAMETER_DESC) ? Ordering.DESCENDING
: Ordering.UNSORTED)));
} else {
column.toggleSortOrder();
}
Collection<Object> sortPriority = table
.getSortPriority();
// clear sort priority in case of single sort mode
if (isSingleSortMode) {
sortPriority.clear();
}
// add column to sort priority if is not added yet
if (!sortPriority.contains(id)) {
sortPriority.add(id);
}
if (isGroupingColumn) {
// set as grouping column to mark that grouping
// order has changed
table.setGroupByColumn(column);
}
} else if (isSingleSortMode) { // in case of single
// sort mode
if (!isGroupingColumn) { // grouping is not by
// this column
if (!sortByGroupingColumn) {// sort not by
// grouping column
// disable sort by this column
column.setSortOrder(Ordering.UNSORTED);
}
}
}
}
UIInput filterValueInput = (UIInput) column
.getFacet(FILTER_INPUT_FACET_NAME);
if (null != filterValueInput) {
filterValueInput.decode(context);
String oldFilterValue = column.getFilterValue();
Object submittedValue = filterValueInput
.getSubmittedValue();
String newFilterValue = null;
if (null != submittedValue) {
newFilterValue = filterValueInput
.getSubmittedValue().toString();
if ((newFilterValue != null)
&& (newFilterValue.length() == 0)) {
newFilterValue = null;
}
column.setFilterValue(newFilterValue);
}
boolean filterChanged = (newFilterValue == null ? (oldFilterValue != null)
: !newFilterValue.equals(oldFilterValue));
// if (filterChanged) {
// //set focus on changed field
// AjaxContext.getCurrentInstance().getResponseDataMap().put(AjaxActionComponent.FOCUS_DATA_ID, filterValueInput.getClientId(context));
// }
filtering = (filtering || filterChanged);
}
}
if (AjaxRendererUtils.isAjaxRequest(context)) {
AjaxRendererUtils.addRegionsFromComponent(table, context);
}
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);
if (sorting){
new ExtTableSortEvent(component).queue();
}
if (filtering){
new ExtTableFilterEvent(component).queue();
}
}
// GROUP COLUMNS
if (GROUP_FILTER_PARAMETER.equals(map.get(clientId))) {
String groupColumnId = map.get(GROUP_FILTER_PARAMETER);
// turn off grouping
table.disableGrouping();
if (groupColumnId != null) {
// turn off sorting by all columns
table.getSortPriority().clear();
for (Iterator<UIColumn> columns = table.getChildColumns(); columns
.hasNext();) {
UIColumn column = columns.next();
// child.setId(child.getId());
if (groupColumnId.equals(column.getClientId(context))) { // group
// by
// this
// column
// set sort order if is not set
if (column.getSortOrder().equals(Ordering.UNSORTED)) {
column.setSortOrder(Ordering.ASCENDING);
}
// set as grouping column
table.setGroupByColumn(column);
} else { // grouping is not by this column
// turn off sorting by this column
column.setSortOrder(Ordering.UNSORTED);
}
}// for columns
}// if
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);
// AjaxContext.getCurrentInstance().addRenderedArea(clientId +
// ":tu");
new ExtTableSortEvent(component).queue();
}// group columns
// CHANGE COLUMN ORDER - DRAG AND DROP
String dragSourceId = (String) map
.get(org.richfaces.renderkit.DraggableRendererContributor.DRAG_SOURCE_ID);
String dropTargetId = (String) map
.get(org.richfaces.renderkit.DropzoneRendererContributor.DROP_TARGET_ID);
if ((dragSourceId != null) && (dropTargetId != null)) {
Pattern sourcePattern = Pattern.compile(clientId + ":(\\w*):"
+ TableDragDropRenderer.DRAG_SOURCE_SCRIPT_ID);
Pattern targetPattern = Pattern.compile(clientId + ":(\\w*):"
+ TableDragDropRenderer.DROP_TARGET_SCRIPT_ID + "("
+ TableDragDropRenderer.DROP_TARGET_BEFORE + "|"
+ TableDragDropRenderer.DROP_TARGET_AFTER + ")");
Matcher sourceMatcher = sourcePattern.matcher(dragSourceId);
Matcher targetMatcher = targetPattern.matcher(dropTargetId);
if (sourceMatcher.find() && targetMatcher.find()) {
String sourceColumnId = sourceMatcher.group(1);
String targetColumnId = targetMatcher.group(1);
String kind = targetMatcher.group(2);
DragDropEvent dragDropEvent = new DragDropEvent(component);
dragDropEvent.setDragValue(sourceColumnId);
dragDropEvent.setDropValue(targetColumnId);
dragDropEvent.setDropBefore(kind
.equals(TableDragDropRenderer.DROP_TARGET_BEFORE));
dragDropEvent.queue();
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);
// AjaxContext ajaxContext =
// AjaxContext.getCurrentInstance();
// ajaxContext.addComponentToAjaxRender(component);
// ajaxContext.addRenderedArea(clientId + ":tb");// body
// ajaxContext.addRenderedArea(clientId + ":tu");
// ajaxContext.addRenderedArea(clientId + ":tm");// menu
// AjaxContext.getCurrentInstance().addRenderedArea(clientId);
}
}// change column order
// CHANGE COLUMN VISIBILITY
String columnToChange = (String) map.get(clientId + ":"
+ TableMenuRenderer.CHANGE_COL_VISIBILITY);
if (columnToChange != null) {
ChangeColumnVisibilityEvent event = new ChangeColumnVisibilityEvent(
component, columnToChange);
event.queue();
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);
// AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
// ajaxContext.addComponentToAjaxRender(component);
// ajaxContext.addRenderedArea(clientId + ":tb");// body
// ajaxContext.addRenderedArea(clientId + ":tu");
// ajaxContext.addRenderedArea(clientId + ":tm");// menu
}// change column visibility
// COLUMN RESIZE
if (COL_RESIZE_ACTION_NAME.equals(map.get(COL_RESIZE_ACTION_NAME))) {
String colWidths = (String) map.get("columnWidths");
ColumnResizeEvent event = new ColumnResizeEvent(component,
colWidths);
event.queue();
}
// TOGGLE ROW GROUP
if (GROUP_TOGGLE_ACTION_NAME.equals(map
.get(GROUP_TOGGLE_ACTION_NAME))) {
String group = (String) map.get("groupIndex");
if (group != null) {
try {
table.toggleGroup(Integer.valueOf(group));
} catch (NumberFormatException _) {
}
}// if
context.renderResponse();
}