#5 Bug in IMG URL String

open
None
5
2006-07-13
2006-07-03
offuttra
No

The URL string outputs HTML & instead of & so none
of the charts display.

Example:

<img id="chart1" width="400" height="300"
src="chartcreatorrequest.jsf?ts=1151959467734&amp;id=chart1"
/>

I am running Jboss portal 2.2.0 and chart creator
1.2.0-RC1.

Discussion

    • assigned_to: nobody --> cagatay_civici
     
  • Logged In: NO

    Here's a proposed fix in ChartRenderer for this bug. Changes include calling writer.writeURIAttribute instead of writer.writeAttribute. It also involves calling encodeURL to get session tracking working properly.

    public class ChartRenderer extends Renderer {

    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    UIChart chart = (UIChart) component;
    setChartDataAtSession(context, chart);

    String clientId = chart.getClientId(context);

    writer.startElement("img", chart);
    writer.writeAttribute("id", clientId, null);
    writer.writeAttribute("width", String.valueOf(chart.getWidth()), null);
    writer.writeAttribute("border", "0", null);
    writer.writeAttribute("height", String.valueOf(chart.getHeight()),null);

    if(ChartUtils.useServlet(context))
    writer.writeURIAttribute("src", encodeUrl(context, ChartConstants.CHART_REQUEST + ".chart?ts="+
    System.currentTimeMillis() + "&chartId=" + clientId), null);
    else {
    String viewId = context.getViewRoot().getViewId();
    String actionURL = context.getApplication().getViewHandler().getActionURL(context, viewId);
    writer.writeURIAttribute("src", encodeUrl(context, actionURL + "?ts="+ System.currentTimeMillis() +
    "&chartId=" + clientId), null);
    }

    ChartUtils.renderPassThruImgAttributes(writer, chart);
    }

    // encodes the url for session tracking, if needed
    private String encodeUrl(FacesContext context, String url) {
    Object response = context.getExternalContext().getResponse();
    if(response instanceof HttpServletResponse) {
    return ((HttpServletResponse)response).encodeURL(url);
    }
    else if(response instanceof RenderResponse) {
    return ((RenderResponse)response).encodeURL(url);
    }

    return url;
    }