Search in sources :

Example 1 with UIRichList

use of org.alfresco.web.ui.common.component.data.UIRichList in project acs-community-packaging by Alfresco.

the class RichListRenderer method encodeChildren.

/**
 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == true) {
        // the RichList component we are working with
        UIRichList richList = (UIRichList) component;
        // prepare the component current row against the current page settings
        richList.bind();
        // collect child column components so they can be passed to the renderer
        List<UIColumn> columnList = new ArrayList<UIColumn>(8);
        for (Iterator i = richList.getChildren().iterator(); i.hasNext(); ) /**/
        {
            UIComponent child = (UIComponent) i.next();
            if (child instanceof UIColumn) {
                columnList.add((UIColumn) child);
            }
        }
        UIColumn[] columns = new UIColumn[columnList.size()];
        columnList.toArray(columns);
        // get the renderer instance
        IRichListRenderer renderer = (IRichListRenderer) richList.getViewRenderer();
        if (renderer == null) {
            throw new IllegalStateException("IRichListRenderer must be available in UIRichList!");
        }
        // call render-before to output headers if required
        ResponseWriter out = context.getResponseWriter();
        out.write("<thead>");
        renderer.renderListBefore(context, richList, columns);
        out.write("</thead>");
        out.write("<tbody>");
        if (richList.isDataAvailable() == true) {
            while (richList.isDataAvailable() == true) {
                // render each row in turn
                renderer.renderListRow(context, richList, columns, richList.nextRow());
            }
        } else {
            // if no items present, render the facet with the "no items found" message
            UIComponent emptyComponent = richList.getEmptyMessage();
            if (emptyComponent != null) {
                emptyComponent.encodeBegin(context);
                emptyComponent.encodeChildren(context);
                emptyComponent.encodeEnd(context);
            }
        }
        // call render-after to output footers if required
        renderer.renderListAfter(context, richList, columns);
        out.write("</tbody>");
    }
}
Also used : UIColumn(org.alfresco.web.ui.common.component.data.UIColumn) ResponseWriter(javax.faces.context.ResponseWriter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) UIRichList(org.alfresco.web.ui.common.component.data.UIRichList)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 UIComponent (javax.faces.component.UIComponent)1 ResponseWriter (javax.faces.context.ResponseWriter)1 UIColumn (org.alfresco.web.ui.common.component.data.UIColumn)1 UIRichList (org.alfresco.web.ui.common.component.data.UIRichList)1