* @return Href for sorting
*/
private Href getSortingHref(HeaderCell headerCell)
{
// costruct Href from base href, preserving parameters
Href href = (Href) this.baseHref.clone();
if (this.paginatedList == null)
{
// add column number as link parameter
if (!this.tableModel.isLocalSort() && (headerCell.getSortName() != null))
{
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORT), headerCell.getSortName());
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORTUSINGNAME), "1");
}
else
{
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORT), headerCell.getColumnNumber());
}
boolean nowOrderAscending = true;
if (headerCell.getDefaultSortOrder() != null)
{
boolean sortAscending = SortOrderEnum.ASCENDING.equals(headerCell.getDefaultSortOrder());
nowOrderAscending = headerCell.isAlreadySorted()
? !this.tableModel.isSortOrderAscending()
: sortAscending;
}
else
{
nowOrderAscending = !(headerCell.isAlreadySorted() && this.tableModel.isSortOrderAscending());
}
int sortOrderParam = nowOrderAscending ? SortOrderEnum.ASCENDING.getCode() : SortOrderEnum.DESCENDING
.getCode();
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_ORDER), 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 (this.tableModel.isSortFullTable() || !this.tableModel.isLocalSort())
{
href.addParameter(encodeParameter(TableTagParameters.PARAMETER_PAGE), 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 = tableModel.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;
}