private static final Log LOG = LogFactory.getLog(SimpleSheetRenderer.class);
@SuppressWarnings(value = "unchecked")
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
UIData data = (UIData) component;
storeFooterHeight(facesContext, data);
if (data.getRowIndex() != -1) {
// TODO: find why this is needed
LOG.warn("reset RowIndex");
data.setRowIndex(-1);
}
HtmlRendererUtil.createHeaderAndBodyStyles(facesContext, data);
final String sheetId = data.getClientId(facesContext);
HtmlStyleMap sheetStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE);
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
// Outher list div
writer.startElement(HtmlConstants.DIV, null);
writer.writeIdAttribute(sheetId + "_outer_div");
writer.writeClassAttribute("tobago-simpleSheet-content");
writer.writeStyleAttribute(sheetStyle);
UICommand clickAction = null;
UICommand dblClickAction = null;
int columnSelectorIndex = -1;
int i = 0;
for (UIComponent child : (List<UIComponent>) data.getChildren()) {
if (child instanceof UIColumnEvent) {
UIColumnEvent columnEvent = (UIColumnEvent) child;
if (columnEvent.isRendered()) {
UIComponent selectionChild = (UIComponent) child.getChildren().get(0);
if (selectionChild != null && selectionChild instanceof UICommand && selectionChild.isRendered()) {
UICommand action = (UICommand) selectionChild;
if ("click".equals(columnEvent.getEvent())) {
clickAction = action;
}
if ("dblclick".equals(columnEvent.getEvent())) {
dblClickAction = action;
}
}
}
} else if (child instanceof UIColumnSelector) {
columnSelectorIndex = i;
}
i++;
}
renderSheet(facesContext, data, (clickAction != null || dblClickAction != null));
writer.endElement(HtmlConstants.DIV);
ResourceManager resourceManager = ResourceManagerFactory.getResourceManager(facesContext);
UIViewRoot viewRoot = facesContext.getViewRoot();
String contextPath = facesContext.getExternalContext().getRequestContextPath();
String unchecked = contextPath + resourceManager.getImage(viewRoot, "image/sheetUnchecked.gif");
String checked = contextPath + resourceManager.getImage(viewRoot, "image/sheetChecked.gif");
boolean ajaxEnabled = TobagoConfig.getInstance(facesContext).isAjaxEnabled();
final String[] styles = new String[]{"style/tobago-sheet.css"};
final String[] scripts = new String[]{"script/tobago-sheet.js"};
Integer frequency = null;
UIComponent facetReload = data.getFacet(TobagoConstants.FACET_RELOAD);
if (facetReload != null && facetReload instanceof UIReload && facetReload.isRendered()) {
UIReload update = (UIReload) facetReload;
frequency = update.getFrequency();
}
final String[] cmds = {
"new Tobago.Sheet(\"" + sheetId + "\", " + ajaxEnabled
+ ", \"" + checked + "\", \"" + unchecked + "\", \"" + data.getSelectable()
+ "\", " + columnSelectorIndex + ", "+ frequency
+ ", " + (clickAction!=null?HtmlRendererUtil.getJavascriptString(clickAction.getId()):null)
+ ", " + HtmlRendererUtil.getRenderedPartiallyJavascriptArray(facesContext, clickAction)
+ ", " + (dblClickAction!=null?HtmlRendererUtil.getJavascriptString(dblClickAction.getId()):null)
+ ", " + HtmlRendererUtil.getRenderedPartiallyJavascriptArray(facesContext, dblClickAction)