Search in sources :

Example 71 with ResponseWriter

use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.

the class ImagePickerRadioRenderer method encodeBegin.

/**
 * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    // setup counters
    this.columns = 1;
    this.position = 0;
    this.open = false;
    this.imageSelected = false;
    ResponseWriter out = context.getResponseWriter();
    UIImagePicker imagePicker = (UIImagePicker) component;
    Map attrs = imagePicker.getAttributes();
    out.write("<table cellpadding='0'");
    outputAttribute(out, attrs.get("spacing"), "cellspacing");
    outputAttribute(out, attrs.get("styleClass"), "class");
    outputAttribute(out, attrs.get("style"), "style");
    out.write(">\n");
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) Map(java.util.Map) UIImagePicker(org.alfresco.web.ui.common.component.UIImagePicker)

Example 72 with ResponseWriter

use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.

the class ModeListRenderer 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()) {
        return;
    }
    UIModeList list = (UIModeList) component;
    ResponseWriter out = context.getResponseWriter();
    // get the child components
    for (Iterator i = list.getChildren().iterator(); i.hasNext(); ) /**/
    {
        UIComponent child = (UIComponent) i.next();
        if (child instanceof UIListItems) {
            // get the value of the list items component and iterate
            // through it's collection
            Object listItems = ((UIListItems) child).getValue();
            if (listItems instanceof Collection) {
                Iterator iter = ((Collection) listItems).iterator();
                while (iter.hasNext()) {
                    UIListItem item = (UIListItem) iter.next();
                    if (item.isRendered()) {
                        renderItem(context, out, list, item);
                    }
                }
            }
        } else if (child instanceof UIListItem && child.isRendered()) {
            // found a valid UIListItem child to render
            renderItem(context, out, list, (UIListItem) child);
        }
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) Collection(java.util.Collection)

Example 73 with ResponseWriter

use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.

the class ModeListRenderer method encodeBegin.

/**
 * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    UIModeList list = (UIModeList) component;
    ResponseWriter out = context.getResponseWriter();
    Map attrs = list.getAttributes();
    if (!list.isMenu()) {
        // start outer table container the list items
        out.write("<table cellspacing='1' cellpadding='0'");
        outputAttribute(out, attrs.get("styleClass"), "class");
        outputAttribute(out, attrs.get("style"), "style");
        outputAttribute(out, attrs.get("width"), "width");
        out.write('>');
        // horizontal rendering outputs a single row with each item as a column cell
        if (list.isHorizontal()) {
            out.write("<tr>");
        }
        // output title row if present
        if (list.getLabel() != null) {
            // first column contains an icon if present, second column contains text
            if (!list.isHorizontal()) {
                out.write("<tr>");
            }
            out.write("<td><table cellpadding='0' style='width:100%;'");
            outputAttribute(out, attrs.get("itemSpacing"), "cellspacing");
            out.write("><tr>");
            // output icon column
            if (list.getIconColumnWidth() != 0) {
                out.write("<td style='width:");
                out.write(String.valueOf(list.getIconColumnWidth()));
                out.write("px'></td>");
            }
            // output title label
            out.write("<td><span");
            outputAttribute(out, attrs.get("labelStyle"), "style");
            outputAttribute(out, attrs.get("labelStyleClass"), "class");
            out.write('>');
            out.write(Utils.encode(list.getLabel()));
            out.write("</span></td></tr></table></td>");
            if (!list.isHorizontal()) {
                out.write("</tr>");
            }
        }
    } else {
        // render as a pop-up menu
        // TODO: show the image set for the individual item if available?
        out.write("<table cellspacing='0' cellpadding='0' style='white-space:nowrap'><tr>");
        String selectedImage = (String) attrs.get("selectedImage");
        if (selectedImage != null) {
            out.write("<td style='padding-right:4px'>");
            out.write(Utils.buildImageTag(context, selectedImage, null, "middle"));
            out.write("</td>");
        }
        String menuId = UIMenu.getNextMenuId(list, context);
        out.write("<td style='white-space: nowrap;'><a href='#' onclick=\"javascript:_toggleMenu(event, '");
        out.write(menuId);
        out.write("');return false;\">");
        // use default label if available
        String label = list.getLabel();
        if (label == null || label.length() == 0) {
            // else get the child components and walk to find the selected
            for (Iterator i = list.getChildren().iterator(); i.hasNext(); ) /**/
            {
                UIComponent child = (UIComponent) i.next();
                if (child instanceof UIListItems) {
                    // get the value of the list items component and iterate
                    // through it's collection
                    Object listItems = ((UIListItems) child).getValue();
                    if (listItems instanceof Collection) {
                        Iterator iter = ((Collection) listItems).iterator();
                        while (iter.hasNext()) {
                            UIListItem item = (UIListItem) iter.next();
                            // if selected render as the label
                            if (item.getValue().equals(list.getValue())) {
                                label = item.getLabel();
                                break;
                            }
                        }
                    }
                } else if (child instanceof UIListItem && child.isRendered()) {
                    // found a valid UIListItem child to render
                    UIListItem item = (UIListItem) child;
                    // if selected render as the label
                    if (item.getValue().equals(list.getValue())) {
                        label = item.getLabel();
                        break;
                    }
                }
            }
        }
        // render the label
        if (label != null && label.length() != 0) {
            out.write("<span");
            outputAttribute(out, attrs.get("labelStyle"), "style");
            outputAttribute(out, attrs.get("labelStyleClass"), "class");
            out.write('>');
            out.write(Utils.encode(label));
            out.write("</span>&nbsp;");
        }
        // output image
        if (list.getMenuImage() != null) {
            out.write(Utils.buildImageTag(context, list.getMenuImage(), null, "-4px"));
        }
        out.write("</a></td></tr></table>");
        // output the hidden DIV section to contain the menu item table
        out.write("<div id='");
        out.write(menuId);
        out.write("' style='position:absolute;display:none;padding-left:2px;'>");
        // start outer table container the list items
        out.write("<table cellspacing='1' cellpadding='0'");
        outputAttribute(out, attrs.get("styleClass"), "class");
        outputAttribute(out, attrs.get("style"), "style");
        outputAttribute(out, attrs.get("width"), "width");
        out.write('>');
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) Collection(java.util.Collection) Map(java.util.Map)

Example 74 with ResponseWriter

use of javax.faces.context.ResponseWriter 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)

Example 75 with ResponseWriter

use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.

the class RichListRenderer method encodeEnd.

/**
 * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    // always check for this flag - as per the spec
    if (component.isRendered() == true) {
        ResponseWriter out = context.getResponseWriter();
        out.write("</table>");
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter)

Aggregations

ResponseWriter (javax.faces.context.ResponseWriter)88 Map (java.util.Map)16 UIComponent (javax.faces.component.UIComponent)14 FacesContext (javax.faces.context.FacesContext)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 ResourceBundle (java.util.ResourceBundle)10 NodeService (org.alfresco.service.cmr.repository.NodeService)10 Iterator (java.util.Iterator)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 List (java.util.List)7 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)5 UserTransaction (javax.transaction.UserTransaction)5 UIModeList (org.alfresco.web.ui.common.component.UIModeList)5 Serializable (java.io.Serializable)4 Node (org.alfresco.web.bean.repository.Node)4 QuickSort (org.alfresco.web.data.QuickSort)3 UIListItem (org.alfresco.web.ui.common.component.UIListItem)3