6 Replies Latest reply on Oct 18, 2006 2:24 PM by mholzner

    How do I output a HTML comment in the head-tag via header-co

    wa7son

      In jboss-portlet.xml, the tag <header-content> holds all tags that needs to be injected into the portals head tag. This can for example be CSS or JavaScript tags.

      But in my situation I also need to output the following HTML comment (i.e. <!--- ... -->):

      <!--[if lt IE 7.]>
      <script src="/javascripts/pngfix.js" type="text/javascript">// foobar</script>
      <![endif]-->
      

      The comment in the XML is of cause interpreted as an XML comment and is just ignored and therefore not outputted. Is there a way to escape the comment to that the XML reader just forwards it to the HTML?

        • 1. Re: How do I output a HTML comment in the head-tag via heade
          theute

          Not sure what you aretrying to do but did you try surrounding it with CDATA ?

          <![CDATA[
          <!--[if lt IE 7.]>
          <script src="/javascripts/pngfix.js" type="text/javascript">// foobar</script>
          <![endif]-->
          ]]>
          


          • 2. Re: How do I output a HTML comment in the head-tag via heade
            wa7son

             

            "thomas.heute@jboss.com" wrote:
            Not sure what you aretrying to do but did you try surrounding it with CDATA ?


            Yes... In that case it is not injected to the head tag at all.

            I tried two ways, both of which did not work:
            <![CDATA[<!--[if lt IE 7.]>]]>
            <script src="/javascripts/pngfix.js" type="text/javascript" defer="defer">// foobar</script>
            <![CDATA[<![endif]-->]]>
            

            and as you suggested:
            <![CDATA[
            <!--[if lt IE 7.]>
            <script src="/javascripts/pngfix.js" type="text/javascript" defer="defer">// foobar</script>
            <![endif]-->
            ]]>
            


            What I am trying to achive is to insert what is called "conditional comments", but the problem is basically to insert any HTML comment at all.

            For more info on conditional comments see:
            http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp
            http://virtuelvis.com/archives/2004/02/css-ie-only

            • 3. Re: How do I output a HTML comment in the head-tag via heade
              wa7son

              Btw... This is the complete jboss-portlet.xml file:

              <portlet-app>
               <portlet>
               <portlet-name>ProductionUnitPortlet</portlet-name>
               <remotable>true</remotable>
               <header-content>
               <link href="/stylesheets/eogs.css" title="" rel="stylesheet" type="text/css" media="screen" />
               <link href="/stylesheets/calendar/calendar-win2k-1.css" title="calendar-win2k-1" rel="stylesheet" type="text/css" media="all" />
               <script src="/javascripts/popup.js" type="text/javascript" defer="defer">// foobar</script>
               <![CDATA[
               <!--[if lt IE 7.]>
               <script src="/javascripts/pngfix.js" type="text/javascript" defer="defer">// foobar</script>
               <![endif]-->
               ]]>
               </header-content>
               <security></security>
              <!-- <transaction>
               <trans-attribute>Required</trans-attribute>
               </transaction> -->
               </portlet>
              </portlet-app>
              


              • 4. Re: How do I output a HTML comment in the head-tag via heade

                In your case the code is ignored because the xml descriptor is parsed in a standard way (i.e. ignoring comments).

                BUT: You can do it via code. In the portlet's doView() etc. you can inject any HTML you want. Look for the ContentRewritePortlet in the portlet examples (in core).

                 response.setProperty("HEADER_CONTENT", "<your string here>");
                


                You can even wsrp rewrite the content to get namespacing:

                 res.setProperty("WSRP_REWRITE", "true");
                




                • 5. Re: How do I output a HTML comment in the head-tag via heade
                  wa7son

                  As far as I can see this is not possible for me because I'm using MyFaces (and it is MyFaces who control the portlet).

                  My guess is that MyFaces is doing the exact same thing as you are describing, but for some reason, the MyFaces portlet does not get the complete content <header-content> tag. Could it be that some of the content accidentally was filtered / escaped away and therefore lost before added to the HEADER_CONTENT property?

                  • 6. Re: How do I output a HTML comment in the head-tag via heade

                    Currently it is not possible to get what you want via the descriptor.
                    Look at

                    org.jboss.portal.theme.deployment.jboss.PortalThemeMetaDataFactory
                    

                    That's where the descriptor gets unmarshalled. As you can see there, everything but script and link tags will be ignored.

                    Not sure if you could modify your script to be cross browser.