for (Iterator iter = getChildren().iterator(); iter.hasNext();)
{
UIComponent component = (UIComponent) iter.next();
if (component instanceof UIColumn)
{
UIColumn aColumn = (UIColumn) component;
UIComponent headerFacet = aColumn.getHeader();
boolean replaceHeaderFacets = isSortable(); //if the table is sortable, all
//header facets can be changed if needed
String columnName = null;
String propertyName = null;
boolean defaultSorted = false;
if (aColumn instanceof HtmlSimpleColumn)
{
HtmlSimpleColumn asColumn = (HtmlSimpleColumn) aColumn;
propertyName = asColumn.getSortPropertyName();
defaultSorted = asColumn.isDefaultSorted();
if (asColumn.isSortable())
replaceHeaderFacets = true;
}
//replace header facet with a sortable header component if needed
if (replaceHeaderFacets && isSortHeaderNeeded(aColumn, headerFacet))
{
propertyName = propertyName != null ? propertyName : getSortPropertyFromEL(aColumn);
if (propertyName == null)
log.warn("Couldn't determine sort property for column [" + aColumn.getId() + "].");
if (headerFacet instanceof UIPanel)
{
// 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() + "].");
}
//make the column marked as default sorted be the current sorted column
//When getSortColumn() eval to a ValueExpression and it is a String, it could return
//null but here it is coerced to "", so we need to assume "" as null.