@Override
protected void preRenderParent(FacesContext facesContext, UIComponent component) {
AbstractPlaceholder placeholder = (AbstractPlaceholder) component;
UIComponent parent = component.getParent();
PlaceholderRendererBase renderer = (PlaceholderRendererBase) placeholder.getRenderer(facesContext);
String placeHolderStyleClass = (String) component.getAttributes().get("styleClass");
if (! Strings.isNullOrEmpty(placeHolderStyleClass)) {
parent.getAttributes().put("placeHolderStyleClass", placeHolderStyleClass);
}
if (parent instanceof InplaceComponent) {
if (placeholder.isRendered() && placeholder.getValue() != null) {
// backup defaultLabel attribute
ValueExpression originalExpression = parent.getValueExpression("defaultLabel");
if (originalExpression != null) {
parent.getAttributes().put("originalDefaultLabel", originalExpression);
} else if (((InplaceComponent) parent).getDefaultLabel() != null) {
parent.getAttributes().put("originalDefaultLabel", ((InplaceComponent) parent).getDefaultLabel());
}
String text = renderer.getConvertedValue(facesContext, placeholder);
((InplaceComponent) parent).setDefaultLabel(text);
} else {
Object defaultLabel = parent.getAttributes().get("originalDefaultLabel");
((InplaceComponent) parent).setDefaultLabel(null);
if (defaultLabel instanceof ValueExpression) {
parent.setValueExpression("defaultLabel", (ValueExpression) defaultLabel);
} else if (defaultLabel != null) {
((InplaceComponent) parent).setDefaultLabel((String) defaultLabel);
}
}
} else {
try {
if (component.isRendered()) {
renderer.doEncodeEnd(facesContext.getResponseWriter(), facesContext, component);
}
} catch (Exception e) {
throw new IllegalStateException("Rendering of placeholder before its parent has failed", e);
}
}