we are using JSF and are building some javascript code in our backend using the below:
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: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"); } } } } }
the output code on the jsp page looks like this: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).
If I change all the < to < and all the > > 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?Code:<h:outputText value="#{Rhs.rhsItem}" escape="false" />
thanks!!


Reply With Quote
Bookmarks