* @return Href for sorting
*/
private Href getSortingHref(HeaderCell headerCell, TableModel model)
{
// costruct Href from base href, preserving parameters
Href href = (Href) this.baseHref.clone();
if (model.getForm() != null)
{
href = new PostHref(href, model.getForm());
}
if (this.paginatedList == null)
{
// add column number as link parameter
if (!model.isLocalSort() && (headerCell.getSortName() != null))
{
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORT, model), headerCell.getSortName());
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORTUSINGNAME, model), "1");
}
else
{
href.addParameter(
encodeParameter(TableTagParameters.PARAMETER_SORT, model),
headerCell.getColumnNumber());
}
boolean nowOrderAscending = true;
if (headerCell.getDefaultSortOrder() != null)
{
boolean sortAscending = SortOrderEnum.ASCENDING.equals(headerCell.getDefaultSortOrder());
nowOrderAscending = headerCell.isAlreadySorted() ? !model.isSortOrderAscending() : sortAscending;
}
else
{
nowOrderAscending = !(headerCell.isAlreadySorted() && model.isSortOrderAscending());
}
int sortOrderParam = nowOrderAscending ? SortOrderEnum.ASCENDING.getCode() : SortOrderEnum.DESCENDING
.getCode();
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_ORDER, model), sortOrderParam);
// If user want to sort the full table I need to reset the page number.
// or if we aren't sorting locally we need to reset the page as well.
if (model.isSortFullTable() || !model.isLocalSort())
{
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_PAGE, model), 1);
}
}
else
{
if (properties.getPaginationSkipPageNumberInSort())
{
href.removeParameter(properties.getPaginationPageNumberParam());
}
String sortProperty = headerCell.getSortProperty();
if (sortProperty == null)
{
sortProperty = headerCell.getBeanPropertyName();
}
href.addParameter(properties.getPaginationSortParam(), sortProperty);
String dirParam;
if (headerCell.isAlreadySorted())
{
dirParam = model.isSortOrderAscending() ? properties.getPaginationDescValue() : properties
.getPaginationAscValue();
}
else
{
dirParam = properties.getPaginationAscValue();
}
href.addParameter(properties.getPaginationSortDirectionParam(), dirParam);
if (paginatedList.getSearchId() != null)
{
href.addParameter(properties.getPaginationSearchIdParam(), paginatedList.getSearchId());
}
}
return href;
}