// Theorically this method should always return null, but it is known
// than in some cases (portlet) when the state manager is different from
// the default one, transient components are saved on the component tree.
// Really the error is on the jsf portlet bridge implementation used, but
// do this does not cause any side effect.
HtmlCommandLink link = (HtmlCommandLink) scroller.findComponent(scroller.getId() + facetName);
if (link == null)
{
// See Jira Issue TOMAHAWK-117 http://issues.apache.org/jira/browse/TOMAHAWK-117
// and http://issues.apache.org/jira/browse/MYFACES-1809
link = new org.apache.myfaces.component.html.ext.HtmlCommandLink();
//Copy all client behaviors
for (Map.Entry<String,List<ClientBehavior>> entry : scroller.getClientBehaviors().entrySet())
{
List<ClientBehavior> list = entry.getValue();
if (list != null && !list.isEmpty())
{
for (ClientBehavior cb : list)
{
link.addClientBehavior(entry.getKey(), cb);
}
}
}
link.setId(scroller.getId() + facetName);
link.setTransient(true);
UIParameter parameter = (UIParameter) application
.createComponent(UIParameter.COMPONENT_TYPE);
parameter.setId(scroller.getId() + facetName + "_param");
parameter.setTransient(true);
// TOMAHAWK-96 Data table Scroller not working the dataTable which was actually
// contained in other DataTable.
// Since the parent link is always the scroller, we can just use a value expression
// that calculates its id, so when the datascroller is rendered per row, the clientId
// is calculated based on the row position.
//parameter.setName(scroller.getClientId(facesContext));
parameter.setValueExpression("name", facesContext.getApplication().
getExpressionFactory().createValueExpression(facesContext.getELContext(),
"#{component.parent.clientId}", String.class));
parameter.setValue(facetName);
List children = link.getChildren();
children.add(parameter);
scroller.getChildren().add(link);
}
return link;
}