{
// In jsf 2.0, facets allow more than one component. That causes a side effect on
// facelets mode when auto wrapping is used, because the algorithm is not aware
// we wrap everything inside a HtmlCommandSortHeader. We have to check
// here that condition and if so, fix it and threat it correctly.
HtmlCommandSortHeader sortHeader = null;
for (UIComponent childHeaderFacet : headerFacet.getChildren())
{
if (childHeaderFacet instanceof HtmlCommandSortHeader)
{
sortHeader = (HtmlCommandSortHeader) childHeaderFacet;
break;
}
}
if (sortHeader != null)
{
aColumn.getFacets().remove("header");
aColumn.setHeader(sortHeader);
headerFacet = sortHeader;
//command sort headers are already in place, just store the column name and sort property name
columnName = sortHeader.getColumnName();
propertyName = sortHeader.getPropertyName();
//if the command sort header component doesn't specify a sort property, determine it
if (propertyName == null)
{
propertyName = getSortPropertyFromEL(aColumn);
sortHeader.setPropertyName(propertyName);
}
if (propertyName == null)
log.warn("Couldn't determine sort property for column [" + aColumn.getId() + "].");
}
}
if (headerFacet != null && isSortHeaderNeeded(aColumn, headerFacet))
{
// We need to force PreRemoveFromViewEvent on the wrapped facet, so we remove it manually here.
// Otherwise the component is just moved on the view and no event is triggered.
aColumn.getFacets().remove("header");
HtmlCommandSortHeader sortHeader = createSortHeaderComponent(context, aColumn, headerFacet, propertyName);
columnName = sortHeader.getColumnName();
aColumn.setHeader(sortHeader);
//setParent is called internally!
//sortHeader.setParent(aColumn);
}
}
else if (headerFacet instanceof HtmlCommandSortHeader)
{
//command sort headers are already in place, just store the column name and sort property name
HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) headerFacet;
columnName = sortHeader.getColumnName();
propertyName = sortHeader.getPropertyName();
//if the command sort header component doesn't specify a sort property, determine it
if (propertyName == null)
{
propertyName = getSortPropertyFromEL(aColumn);
sortHeader.setPropertyName(propertyName);
}
if (propertyName == null)
log.warn("Couldn't determine sort property for column [" + aColumn.getId() + "].");
}