0 Replies Latest reply on Sep 1, 2010 1:24 PM by John Ericksen

    s:download ui component css styleClass rendering bug

    John Ericksen Newbie

      I found a bug that I want to highlight in seam version 2.2.1-CR2 (and previous) with the download component.  Looks like the styleClass attribute renders out to 'styleclass' instead of the expected 'class' attribute.


      Here's the example:


      <s:download styleClass="stylin" src="resource.jspx">
        <h:outputText value="Download link"/>
        <f:param name="id" value="#{id}/>
      </s:download>
      



      renders to the following HTML:


      <a href="/application/resource.jspx?id=1" styleclass="stylin">Download link</a>
      



      From reviewing the seam code it looks liek this is a combination of problems between not wanting to name the css class 'class' and not fixing it before rending the html as follows:


      org.jboss.seam.ui.renderkit.DownloadRendererBase lines 65 - 73:



         private void writeStartTag(javax.faces.context.ResponseWriter writer, UIDownload download, String url) throws IOException
         {
            writer.startElement(HTML.ANCHOR_ELEM, null);
            writer.writeAttribute(HTML.HREF_ATTR, url, null);
            if (download.getStyle() != null)
               writer.writeAttribute(HTML.STYLE_ATTR, download.getStyle(), null);
            if (download.getStyleClass() != null)
               writer.writeAttribute(HTML.STYLE_CLASS_ATTR, download.getStyleClass(), null);
         }




      org.jboss.seam.ui.uti.HTML lines 190 - 194:




         // universal attributes
          public static final String DIR_ATTR   = "dir";
          public static final String LANG_ATTR  = "lang";
          public static final String STYLE_ATTR = "style";
          public static final String TITLE_ATTR = "title";
          public static final String STYLE_CLASS_ATTR = "styleClass"; //"class" cannot be used as property name
      




      lines 65 - 73 of org.jboss.seam.ui.renderkit.DownloadRendererBase should probably be:




         private void writeStartTag(javax.faces.context.ResponseWriter writer, UIDownload download, String url) throws IOException
         {
            writer.startElement(HTML.ANCHOR_ELEM, null);
            writer.writeAttribute(HTML.HREF_ATTR, url, null);
            if (download.getStyle() != null)
               writer.writeAttribute(HTML.STYLE_ATTR, download.getStyle(), null);
            if (download.getStyleClass() != null)
               writer.writeAttribute(HTML.CLASS_ATTR, download.getStyleClass(), null); //<-- class instead of styleclass
         }
      



      I would be happy to file a bug report and patch if necessary.  Thanks.


      By the way, there is an easy css fix for this to apply a style to this a tag that we had to use to bridge this issue.  Instead of using the following:


      a.icon{
          background: transparent url("../images/ico.gif") no-repeat center left;
          display:block;
          padding: 4px 0 2px 18px;
          font-weight: normal;
      }
      


      you can use the following css:


      span.icon a{
          background: transparent url("../images/excel.gif") no-repeat center left;
          display:block;
          padding: 4px 0 2px 18px;
          font-weight: normal;
      }



      along with wrapping the s:download a link as follows:




      <span class="icon">
        <s:download src="resource.jspx">
          <h:outputText value="Download link"/>
          <f:param name="id" value="#{id}/>
        </s:download>
      </span>