* sort direction
* @throws IOException
*/
protected void buildSortMenuItem(UIComponent parent, boolean asc)
throws IOException {
UIMenuItem menuItem = (UIMenuItem) context.getApplication()
.createComponent(UIMenuItem.COMPONENT_TYPE);
menuItem.setSubmitMode("none");
String ascStr = asc ? "asc" : "desc";
menuItem.setId(getId("sort_" + asc));
String actionScript = null;
StringBuilder actionScriptBuilder = new StringBuilder();
if ((Boolean) column.getAttributes().get("sortable")) {
if (sortFunction != null) {
if (prepareFunction != null) {
actionScriptBuilder.append(prepareFunction.toScript())
.append("; ");
}
actionScriptBuilder.append(sortFunction.toScript());
actionScript = actionScriptBuilder.toString();
if (actionScript.contains("{columnId}")) {
String columnClientId = (String) column.getAttributes()
.get("columnClientId");
if (columnClientId == null)
columnClientId = column.getClientId(context);
actionScript = actionScript.replace("{columnId}",
columnClientId);
}
if (actionScript.contains("{sortDirection}")) {
actionScript = actionScript.replace("{sortDirection}", ascStr);
}
}
} else {
menuItem.setDisabled(true);
}
menuItem.setValue(ComponentMessageUtil.getMessage(context,
(asc ? MSG_SORT_ASC : MSG_SORT_DESC), new Object[] {})
.getSummary());
menuItem.setIcon((asc ? iconSortAscURI : iconSortDescURI));
if (menuItem instanceof HtmlMenuItem) {
((HtmlMenuItem) menuItem)
.setOnclick(actionScript == null ? "return false;"
: actionScript);
}