From 9e40f4182456e99247210f51a1f52f78afca9679 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 2 Feb 2007 17:33:31 +0000 Subject: [PATCH] . Fix for http://issues.alfresco.com/browse/WCM-267 and http://issues.alfresco.com/browse/WCM-238 - Improvement to alignment/wrapping issues with dynamic HTML DIV menus in IE . Refactor of ActionLinkRenderer code, fixes subtle alignment issues in IE and improves performance git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5023 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../common/renderer/ActionLinkRenderer.java | 456 +++++++++--------- source/web/jsp/wcm/browse-sandbox.jsp | 4 +- source/web/jsp/wcm/browse-website.jsp | 2 +- 3 files changed, 225 insertions(+), 237 deletions(-) diff --git a/source/java/org/alfresco/web/ui/common/renderer/ActionLinkRenderer.java b/source/java/org/alfresco/web/ui/common/renderer/ActionLinkRenderer.java index c8b39c81a4..8d2a2dac00 100644 --- a/source/java/org/alfresco/web/ui/common/renderer/ActionLinkRenderer.java +++ b/source/java/org/alfresco/web/ui/common/renderer/ActionLinkRenderer.java @@ -79,25 +79,32 @@ public class ActionLinkRenderer extends BaseRenderer { return; } - Writer out = context.getResponseWriter(); + UIActionLink link = (UIActionLink)component; + + // if there is no value for the link there will be no visible output + // on the page so don't bother rendering anything + if (link.getValue() != null) + { + Writer out = context.getResponseWriter(); - UIComponent verticalContiner = getVerticalContainer(link); - if (verticalContiner != null) - { - int padding = link.getPadding(); - - if (verticalContiner instanceof UIActions) + UIComponent verticalContiner = getVerticalContainer(link); + if (verticalContiner != null) { - padding = ((UIActions)verticalContiner).getVerticalSpacing(); + int padding = link.getPadding(); + + if (verticalContiner instanceof UIActions) + { + padding = ((UIActions)verticalContiner).getVerticalSpacing(); + } + // render as menu item style action link + renderMenuAction(context, out, link, padding); + } + else + { + // render as action link + renderActionLink(context, out, link); } - // render as menu item style action link - out.write( renderMenuAction(context, link, padding) ); - } - else - { - // render as action link - out.write( renderActionLink(context, link) ); } } @@ -106,161 +113,151 @@ public class ActionLinkRenderer extends BaseRenderer * * @param context * @param link - * - * @return action link HTML */ - private String renderActionLink(FacesContext context, UIActionLink link) + private void renderActionLink(FacesContext context, Writer out, UIActionLink link) + throws IOException { - // if there is no value for the link there will be no visible output - // on the page so don't bother rendering anything - String linkHtml = ""; - Object linkValue = link.getValue(); - - if (linkValue != null) + // output the action link - with an image icon if specified, else just the text link part + String image = link.getImage(); + if (image != null) { - Map attrs = link.getAttributes(); - StringBuilder linkBuf = new StringBuilder(256); - - if (link.getHref() == null) + int padding = link.getPadding(); + if (padding != 0) { - linkBuf.append(""); } else { - String href = link.getHref(); - - // prefix the web context path if required - linkBuf.append("'); - - StringBuilder buf = new StringBuilder(350); - if (link.getImage() != null) - { - int padding = link.getPadding(); if (padding != 0) { - // TODO: make this width value a property! - buf.append("
"); + out.write(""); } - if (link.getShowLink() == false) - { - buf.append(linkBuf.toString()); - } - - // TODO: allow configuring of alignment attribute - buf.append(Utils.buildImageTag(context, link.getImage(), (String)link.getValue(), "absmiddle")); - - if (link.getShowLink() == false) - { - buf.append(""); - } - else - { - if (padding != 0) - { - buf.append(""); - } - else - { - // TODO: add horizontal spacing as component property - buf.append(""); - } - - buf.append(linkBuf.toString()); - buf.append(Utils.encode(link.getValue().toString())); - buf.append(""); - - if (padding == 0) - { - buf.append(""); - } - } - - if (padding != 0) - { - buf.append("
"); - } + // else the text is the clickable element + renderActionLinkAnchor(context, out, link); + out.write(Utils.encode(link.getValue().toString())); + out.write("
"); + } + + if (padding != 0) + { + out.write(""); + } + } + else + { + // no image, so text is the clickable element + renderActionLinkAnchor(context, out, link); + out.write(Utils.encode(link.getValue().toString())); + out.write(""); + } + } + + /** + * Render ActionLink as plain link and image + * + * @param context + * @param link + */ + private void renderActionLinkAnchor(FacesContext context, Writer out, UIActionLink link) + throws IOException + { + Map attrs = link.getAttributes(); + + // generate the href link - output later in the process depending on various rendering options + if (link.getHref() == null) + { + out.write(""); + // generate JavaScript to set a hidden form field and submit + // a form which request attributes that we can decode + out.write(Utils.generateFormSubmit(context, link, Utils.getActionHiddenFieldName(context, link), link.getClientId(context), getParameterComponents(link))); } - linkHtml = buf.toString(); + out.write('"'); + } + else + { + String href = link.getHref(); + + // prefix the web context path if required + out.write("'); } /** @@ -268,7 +265,8 @@ public class ActionLinkRenderer extends BaseRenderer * @param linkBuf * @param href */ - private void renderHrefParams(UIActionLink link, StringBuilder linkBuf, String href) + private void renderHrefParams(UIActionLink link, Writer out, String href) + throws IOException { // append arguments if specified Map actionParams = getParameterComponents(link); @@ -280,16 +278,18 @@ public class ActionLinkRenderer extends BaseRenderer String paramValue = actionParams.get(name); if (first) { - linkBuf.append('?'); + out.write('?'); first = false; } else { - linkBuf.append('&'); + out.write('&'); } try { - linkBuf.append(name).append("=").append(URLEncoder.encode(paramValue, "UTF-8")); + out.write(name); + out.write("="); + out.write(URLEncoder.encode(paramValue, "UTF-8")); } catch (UnsupportedEncodingException err) { @@ -304,90 +304,78 @@ public class ActionLinkRenderer extends BaseRenderer * * @param context * @param link - * - * @return action link HTML */ - private String renderMenuAction(FacesContext context, UIActionLink link, int padding) + private void renderMenuAction(FacesContext context, Writer out, UIActionLink link, int padding) + throws IOException { - // if there is no value for the link there will be no visible output - // on the page so don't bother rendering anything - String linkHtml = ""; - Object linkValue = link.getValue(); + out.write(""); - if (linkValue != null) + // render image cell first for a menu + if (link.getImage() != null) { - StringBuilder buf = new StringBuilder(256); - - buf.append(""); - - // render image cell first for a menu - if (link.getImage() != null) - { - buf.append(Utils.buildImageTag(context, link.getImage(), (String)link.getValue())); - } - - buf.append(""); - - // render text link cell for the menu - if (link.getHref() == null) - { - buf.append("'); - buf.append(Utils.encode(link.getValue().toString())); - buf.append(""); - - buf.append(""); - - linkHtml = buf.toString(); + out.write(Utils.buildImageTag(context, link.getImage(), (String)link.getValue())); } - return linkHtml; + out.write(""); + } + else + { + out.write(">"); + } + + // render text link cell for the menu + if (link.getHref() == null) + { + out.write("'); + out.write(Utils.encode(link.getValue().toString())); + out.write(""); + + out.write(""); } diff --git a/source/web/jsp/wcm/browse-sandbox.jsp b/source/web/jsp/wcm/browse-sandbox.jsp index a68e811045..f60118cce3 100644 --- a/source/web/jsp/wcm/browse-sandbox.jsp +++ b/source/web/jsp/wcm/browse-sandbox.jsp @@ -74,11 +74,11 @@
- + - + <%-- Create actions menu --%> diff --git a/source/web/jsp/wcm/browse-website.jsp b/source/web/jsp/wcm/browse-website.jsp index 81b709a698..087b4f37b7 100644 --- a/source/web/jsp/wcm/browse-website.jsp +++ b/source/web/jsp/wcm/browse-website.jsp @@ -74,7 +74,7 @@
- + <%-- More actions menu --%>