@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
// UIPanel or UICell (deprecated)
AbstractUIPanel panel = (AbstractUIPanel) component;
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
String clientId = panel.getClientId(facesContext);
writer.startElement(HtmlElements.DIV, panel);
HtmlRendererUtils.renderDojoDndItem(panel, writer, true);
writer.writeIdAttribute(clientId);
writer.writeClassAttribute(Classes.create(panel));
Style style = new Style(facesContext, panel);
// XXX hotfix for panels in sheets
if (style.getPosition() == null) {
style.setPosition(Position.RELATIVE);
}
writer.writeStyleAttribute(style);
if (panel instanceof UIPanel && ((UIPanel) panel).getTip() != null) {
writer.writeAttribute(HtmlAttributes.TITLE, ((UIPanel) panel).getTip(), true);
}
HtmlRendererUtils.encodeContextMenu(facesContext, writer, panel);
// TODO check ajax id
if (facesContext instanceof TobagoFacesContext && !((TobagoFacesContext) facesContext).isAjax()) {
Integer frequency = null;
UIComponent facetReload = panel.getFacet(Facets.RELOAD);
if (facetReload != null && facetReload instanceof UIReload && facetReload.isRendered()) {
UIReload update = (UIReload) facetReload;
frequency = update.getFrequency();
}
if (frequency == null) {
frequency = 0;
}
final String[] cmds = {
"new Tobago.Panel(\"" + clientId + "\", " + true + ", " + frequency + ");"
};
HtmlRendererUtils.writeScriptLoader(facesContext, null, cmds);
}
HtmlRendererUtils.checkForCommandFacet(panel, facesContext, writer);
final Measure borderLeft = panel.getBorderLeft();
final Measure borderRight = panel.getBorderRight();
final Measure borderTop = panel.getBorderTop();
final Measure borderBottom = panel.getBorderBottom();
if (borderLeft.greaterThan(Measure.ZERO) || borderRight.greaterThan(Measure.ZERO)
|| borderTop.greaterThan(Measure.ZERO) || borderBottom.greaterThan(Measure.ZERO)) {
writer.startElement(HtmlElements.DIV, panel);
writer.writeClassAttribute(Classes.create(panel, "content")); // needed to be scrollable inside of the panel