Search in sources :

Example 21 with ResponseWriter

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

the class UIActions method encodeChildren.

/**
 * @see javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
 */
public void encodeChildren(FacesContext context) throws IOException {
    ResponseWriter out = context.getResponseWriter();
    int verticalSpacing = getVerticalSpacing();
    if (verticalSpacing != 0) {
        out.write("<table cellspacing='");
        out.write(verticalSpacing);
        out.write("'");
        if (getAttributes().get(ATTR_STYLE) != null) {
            outputAttribute(out, getAttributes().get(ATTR_STYLE), ATTR_STYLE);
        }
        if (getAttributes().get(ATTR_STYLECLASS) != null) {
            outputAttribute(out, getAttributes().get(ATTR_STYLECLASS), "class");
        }
        out.write(">");
    }
    // use the current context Id to find the correct component group to render
    Map requestMap = getFacesContext().getExternalContext().getRequestMap();
    Object actionContext = requestMap.get(ACTION_CONTEXT);
    String contextId = CONTEXTID_DEFAULT;
    if (actionContext instanceof Node) {
        contextId = ((Node) actionContext).getType().toString();
    }
    for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
    {
        UIComponent child = (UIComponent) i.next();
        if (contextId.equals(child.getAttributes().get("contextId"))) {
            if (logger.isDebugEnabled())
                logger.debug("Rendering actions group for contextId: " + contextId);
            Utils.encodeRecursive(context, child);
            break;
        }
    }
    if (verticalSpacing != 0) {
        out.write("</table>");
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) Node(org.alfresco.web.bean.repository.Node) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) Map(java.util.Map)

Example 22 with ResponseWriter

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

the class UIAjaxTagPicker method encodeBegin.

@SuppressWarnings("unchecked")
@Override
public /**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
void encodeBegin(FacesContext fc) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = fc.getResponseWriter();
    String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
    Map attrs = this.getAttributes();
    ResourceBundle msg = Application.getBundle(fc);
    // get values from submitted value or none selected
    String selectedValues = null;
    String selectedNames = null;
    String selectedItems = null;
    List<NodeRef> submitted = null;
    submitted = (List<NodeRef>) getSubmittedValue();
    if (submitted == null) {
        Object objSubmitted = getValue();
        // special case to submit empty lists on multi-select values
        if ((objSubmitted != null) && (objSubmitted.toString().equals("empty"))) {
            submitted = null;
            this.setValue(null);
        } else {
            submitted = (List<NodeRef>) getValue();
        }
    }
    if (submitted != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            StringBuilder nameBuf = new StringBuilder(128);
            StringBuilder valueBuf = new StringBuilder(128);
            StringBuilder itemBuf = new StringBuilder(256);
            NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
            for (NodeRef value : submitted) {
                String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
                String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
                if (nameBuf.length() != 0) {
                    nameBuf.append(", ");
                    valueBuf.append(",");
                    itemBuf.append(",");
                }
                nameBuf.append(name);
                valueBuf.append(value.toString());
                itemBuf.append(getItemJson(value.toString(), name, icon));
            }
            selectedNames = nameBuf.toString();
            selectedValues = valueBuf.toString();
            selectedItems = "[" + itemBuf.toString() + "]";
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // generate the Ids for our script object and containing DIV element
    String divId = getId();
    String objId = divId + "Obj";
    // generate the script to create and init our script object
    String contextPath = fc.getExternalContext().getRequestContextPath();
    out.write("<script type='text/javascript'>");
    out.write("function init" + divId + "() {");
    out.write(" window." + objId + " = new AlfTagger('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "','" + msg.getString(MSG_ADD) + "','" + msg.getString(MSG_REMOVE) + "');");
    out.write(" window." + objId + ".setChildNavigation(false);");
    if (getDefaultIcon() != null) {
        out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
    }
    if (selectedItems != null) {
        out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
    }
    out.write("}");
    out.write("window.addEvent('domready', init" + divId + ");");
    out.write("</script>");
    // generate the DIV structure for our component as expected by the script object
    out.write("<div id='" + divId + "' class='picker'>");
    out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
    if (selectedValues != null) {
        out.write(selectedValues);
    }
    out.write("'>");
    // current selection displayed as link and message to launch the selector
    out.write(" <div id='" + divId + "-noitems'");
    if (attrs.get("style") != null) {
        out.write(" style=\"");
        out.write((String) attrs.get("style"));
        out.write('"');
    }
    if (attrs.get("styleClass") != null) {
        out.write(" class=");
        out.write((String) attrs.get("styleClass"));
    }
    out.write(">");
    if (isDisabled()) {
        out.write("   <span>");
        if (selectedNames != null) {
            out.write(selectedNames);
        }
        out.write("   </span>");
    } else {
        out.write("  <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
        if (selectedNames == null) {
            if ("".equals(getLabel())) {
                setLabel(msg.getString(MSG_CLICK_TO_SELECT_TAG));
            }
            out.write(getLabel());
        } else {
            out.write(selectedNames);
        }
        out.write("   </a></span>");
    }
    out.write(" </div>");
    // container for item navigation
    out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
    out.write("  <div class='pickerResults'>");
    out.write("   <div class='pickerResultsHeader'>");
    out.write("    <div class='pickerNavControls'>");
    out.write("     <span class='pickerNavUp'>");
    out.write("      <a id='" + divId + "-nav-up' href='#'><img src='");
    out.write(contextPath);
    out.write("/images/icons/arrow_up.gif' border='0' alt='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("' title='");
    out.write(msg.getString(MSG_GO_UP));
    out.write("'></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavBreadcrumb'>");
    out.write("      <span id='" + divId + "-nav-txt' class='pickerNavBreadcrumbText'></span></a>");
    out.write("     </span>");
    out.write("     <span class='pickerNavAddTag'>");
    out.write("      <span class='pickerAddTagIcon'></span>");
    out.write("      <span id='" + divId + "-addTag-linkContainer' class='pickerAddTagLinkContainer'>");
    out.write("       <a href='#' onclick='window." + objId + ".showAddTagForm(); return false;'>");
    out.write(msg.getString(MSG_ADD_A_TAG));
    out.write("</a>");
    out.write("      </span>");
    out.write("      <span id='" + divId + "-addTag-formContainer' class='pickerAddTagFormContainer'>");
    out.write("       <input id='" + divId + "-addTag-box' class='pickerAddTagBox' name='" + divId + "-addTag-box' type='text'>");
    out.write("       <img id='" + divId + "-addTag-ok' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_successful.gif' alt='");
    out.write(msg.getString(MSG_ADD));
    out.write("' title='");
    out.write(msg.getString(MSG_ADD));
    out.write("'>");
    out.write("       <img id='" + divId + "-addTag-cancel' class='pickerAddTagImage' src='");
    out.write(contextPath);
    out.write("/images/office/action_failed.gif' alt='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("' title='");
    out.write(msg.getString(MSG_CANCEL));
    out.write("'>");
    out.write("      </span>");
    out.write("     </span>");
    out.write("     <span id='" + divId + "-nav-add'></span>");
    out.write("    </div>");
    out.write("   </div>");
    // container for item selection
    out.write("   <div>");
    out.write("    <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
    String height = getHeight();
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("    <div id='" + divId + "-results-list' class='pickerResultsList'");
    if (height != null) {
        out.write(" style='height:" + height + "'");
    }
    out.write("></div>");
    out.write("   </div>");
    out.write("  </div>");
    // controls (OK & Cancel buttons etc.)
    out.write("  <div class='pickerFinishControls'>");
    out.write("   <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
    out.write(msg.getString(MSG_OK));
    out.write("</a></div>");
    out.write("   <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
    out.write(msg.getString(MSG_CANCEL));
    out.write("</a></div>");
    out.write("  </div>");
    out.write(" </div>");
    // container for the selected items
    out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
    out.write("</div>");
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) NodeService(org.alfresco.service.cmr.repository.NodeService) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) IOException(java.io.IOException)

Example 23 with ResponseWriter

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

the class UICategoryBrowser method encodeBegin.

/*
    * (non-Javadoc)
    * 
    * @see org.alfresco.web.ui.repo.component.UINavigator#encodeBegin(javax.faces.context.FacesContext)
    */
@Override
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    // TODO: pull width and height from user preferences and/or the main config,
    // if present override below using the style attribute
    ResponseWriter out = context.getResponseWriter();
    CategoryBrowserPluginBean categoryBrowserPluginBean = (CategoryBrowserPluginBean) FacesHelper.getManagedBean(context, CategoryBrowserPluginBean.BEAN_NAME);
    CategoryBrowserBean categoryBrowserBean = (CategoryBrowserBean) FacesHelper.getManagedBean(context, CategoryBrowserBean.BEAN_NAME);
    List<TreeNode> rootNodes = null;
    rootNodes = categoryBrowserPluginBean.getCategoryRootNodes();
    // order the root nodes by the tree label
    if (rootNodes != null && rootNodes.size() > 1) {
        QuickSort sorter = new QuickSort(rootNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    // main container div
    out.write("<div id=\"category-navigator\" class=\"navigator\">");
    // Subcategories parameter
    String includeSub = Application.getMessage(context, "category_browser_plugin_include_subcategories");
    out.write("<input type='checkbox' id='" + SUBCATEGORIES_PARAM + "' name='" + SUBCATEGORIES_PARAM + "' value=1 " + (categoryBrowserBean.isIncludeSubcategories() ? "checked" : "") + "/>");
    out.write("<label for='" + SUBCATEGORIES_PARAM + "'>" + includeSub + "</label>");
    // generate the javascript method to capture the tree node click events
    out.write("<script type=\"text/javascript\">");
    out.write("function treeNodeSelected(nodeRef) {");
    out.write(Utils.generateFormSubmit(context, this, getClientId(context), "nodeRef", true, null));
    out.write("}</script>");
    // generate the active panel containing the tree
    out.write("<div class=\"navigatorPanelBody\">");
    UITree tree = (UITree) context.getApplication().createComponent(UITree.COMPONENT_TYPE);
    tree.setId("tree");
    tree.setRootNodes(rootNodes);
    tree.setRetrieveChildrenUrl(AJAX_URL_START + ".retrieveChildren?");
    tree.setNodeCollapsedUrl(AJAX_URL_START + ".nodeCollapsed?");
    tree.setNodeSelectedCallback("treeNodeSelected");
    tree.setNodeCollapsedCallback("informOfCollapse");
    Utils.encodeRecursive(context, tree);
    out.write("</div>");
    out.write("</div>");
}
Also used : CategoryBrowserPluginBean(org.alfresco.web.bean.ajax.CategoryBrowserPluginBean) QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) CategoryBrowserBean(org.alfresco.web.bean.CategoryBrowserBean)

Example 24 with ResponseWriter

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

the class UIDialogButtons method encodeChildren.

@Override
public void encodeChildren(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    ResponseWriter out = context.getResponseWriter();
    // render the buttons
    for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
    {
        out.write("<tr><td align=\"center\">");
        UIComponent child = (UIComponent) i.next();
        Utils.encodeRecursive(context, child);
        out.write("</td></tr>");
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent)

Example 25 with ResponseWriter

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

the class UIDialogButtons method encodeBegin.

@Override
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    if (this.getChildCount() == 0) {
        // generate all the required buttons the first time
        generateButtons(context);
    }
    ResponseWriter out = context.getResponseWriter();
    out.write("<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\">");
}
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