* @param parent
* parent component for created item
* @throws IOException
*/
protected void buildGroupMenuItem(UIComponent parent) throws IOException {
UIMenuItem menuItem = (UIMenuItem) context.getApplication()
.createComponent(UIMenuItem.COMPONENT_TYPE);
menuItem.setSubmitMode("none");
menuItem.setId(getId("group"));
String actionScript = null;
StringBuilder actionScriptBuilder = new StringBuilder();
boolean isGroupingColumn = column.getId().equalsIgnoreCase(
table.getGroupByColumnId());
if ((Boolean) column.getAttributes().get("sortable")) {
if (groupFunction != null) {
if (prepareFunction != null) {
actionScriptBuilder.append(prepareFunction.toScript()).append("; ");
}
actionScriptBuilder.append(groupFunction.toScript());
actionScript = actionScriptBuilder.toString();
if (actionScript.contains("{columnId}")) {
String columnClientId = (String) column.getAttributes().get("columnClientId");
if (columnClientId == null)
columnClientId = column.getClientId(context);
if (isGroupingColumn) {
columnClientId = "";
}
actionScript = actionScript.replace("{columnId}", columnClientId);
}
}
} else {
menuItem.setDisabled(true);
}
menuItem.setValue(ComponentMessageUtil.getMessage(context,
(isGroupingColumn ? MSG_GROUP_OFF : MSG_GROUP_ON),
new Object[] {}).getSummary());
menuItem.setIcon(iconGroupURI);
if (menuItem instanceof HtmlMenuItem) {
((HtmlMenuItem) menuItem)
.setOnclick(actionScript == null ? "return false;"
: actionScript);
}