www.webdeveloper.com
Results 1 to 2 of 2

Thread: code not validating using jsf

  1. #1
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898

    code not validating using jsf

    we are using JSF and are building some javascript code in our backend using the below:
    Code:
    StringBuilder rhsAdsHtml = new StringBuilder();
    if (cachedRhsAdsObject != null) {
                for (Zone zone : ads.getZones()) {
                    for (Page page : zone.getPages()) {
                        if (page.name.equalsIgnoreCase(rhsPageName)) {
                            for (Position position : page.getPositions()) {
                                logger.debug("Value of adUrl: " + position.getAdUrl());
                                rhsAdsHtml.append("<script type=\"text/javascript\">\r\n");
                                rhsAdsHtml.append("ord = window.ord || Math.floor(Math.random()*1E16);\r\n");
                                rhsAdsHtml.append("document.write('<script type=\"text/javascript\" ");
                                rhsAdsHtml.append("src=\"");
                                rhsAdsHtml.append(position.getAdUrl());
                                rhsAdsHtml.append(";ord=' + ord + '?\">");
                                rhsAdsHtml.append("<\\/script>');\r\n");
                                rhsAdsHtml.append("</script>\r\n");
                                rhsAdsHtml.append("<noscript>\r\n");
                                rhsAdsHtml.append("<a href=\"");
                                rhsAdsHtml.append(position.getAdUrl());
                                rhsAdsHtml.append(";ord=123456789?\" target=\"_blank\">\r\n");
                                rhsAdsHtml.append("<img src=\"");
                                rhsAdsHtml.append(position.getAdUrl());
                                rhsAdsHtml.append(";ord=123456789?\" alt=\"NEED ALT TEXT HERE\" />\r\n");
                                rhsAdsHtml.append("</a>\r\n");
                                rhsAdsHtml.append("</noscript>\r\n");
                            }
                        }
                    }            
                }            
            }
    This displays fine on our page, but when we validate the code to be XHTML compliant, it is failing, and it has to do with the < and > signs I believe. The error the W3C validator throws is:
    Code:
             Line 176,         Column 159:     document type does not allow element "script" here     …ompany;cat=contact_us;pos=RR1;sz=120x207;tile=1;ord=' + ord + '?"><\/script>');                     
                      The element named above was found in a context where it is not allowed.       This could mean that you have incorrectly nested elements -- such as a       "style" element in the "body" section instead of inside "head" -- or       two elements that overlap (which is not allowed).     
                One common cause for this error is the use of XHTML syntax in HTML       documents. Due to HTML's rules of implicitly closed elements, this error       can create cascading effects. For instance, using XHTML's "self-closing"       tags for "meta" and "link" in the "head" section of a HTML document may       cause the parser to infer the end of the "head" section and the       beginning of the "body" section (where "link" and "meta" are not       allowed; hence the reported error).
    the output code on the jsp page looks like this:
    Code:
    <h:outputText value="#{Rhs.rhsItem}" escape="false" />
    If I change all the < to &lt; and all the > &gt; in my backend code, then it passes validation, but the actual <script> code prints out on my page. Could someone help me get this to work?

    thanks!!

  2. #2
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    I got this working, I was missing a closing bracket

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles