13 Replies Latest reply on Jun 18, 2008 9:52 AM by M Chan

    Is header content injection coded in portal 2.4.0 ?

    Vera Mickael Newbie

      Hi,

      I use JBossPortal 2.4.0 and i'm still trying to insert code in html header via RenderResponse API like this :

      RenderResponse rr = getRenderResponse();
      
       rr.addProperty("HEADER_CONTENT", _htmlBuff.toString());


      But this doesn't work, I still have an empty head :

      <head>
       <title>My Layout</title>
       <meta http-equiv="Content-Type" content="text/html;" />
       <link rel='stylesheet' type='text/css' id='main_css' href='/portal-core/themes/phalanx/portal_style.css' />
      <link rel='shortcut icon' href='/portal-core/themes/phalanx/images/favicon.ico' />
       </head>


      I changed my layout (I hadn't understand this before) and I used the one provided inline in the reference guide :

      <%@ taglib uri="/WEB-INF/theme/portal-layout.tld" prefix="p" %>
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
       <title>My Layout</title>
       <meta http-equiv="Content-Type" content="text/html;" />
       <p:theme themeName='phalanx' />
       <p:headerContent />
       </head>
      


      I used debugger in my code and in JBossPortal code. So I know that:
      + in my code the call to addProperty is executed and the value is not null
      + the layout used is the one I specified
      + the headerContent tag is executed

      But I don't understand why my header is still empty.

      So I downloaded JBossPortal src, looked at it and visited it with the debugger. It seemed to me that nothing is done to retreive the data set in response properties for the key "HEADER_CONTENT" and that only header content set by a declarative way is retreived.

      I only found 2 ocurrences of HEADER_CONTENT in JBossPortal source :
      res.setProperty("HEADER_CONTENT", "<script>function wsrp_rewrite_OnFocus(){alert('hello button');}</script>");
      

      and
      /**
       * Constant to set the content that should be injected into the HEAD tag of the pages markup.
       * <p>The content set in a portlet response property with this flag will be injected into the HEAD tag, if the portal
       * layout features the headercontent tag.</p>
       */
       public static final String HEADER_CONTENT = "HEADER_CONTENT";
      


      I wonder if that functionnality is coded ? If I'm wrong, could anyone tell me in which class it is done so that I can use my debugger to find what is my problem.

      Thanks,
      Mickaël



        • 1. Re: Is header content injection coded in portal 2.4.0 ?
          Vera Mickael Newbie

          Hi,

          I finally managed to solve my problem. But I had to write my own tag to insert content in the header via java API.

          I'm still interested in knowing if somebody managed to do the same without coding its own tag. In this case where is the code that do that ?

          Mickaël

          • 2. Re: Is header content injection coded in portal 2.4.0 ?
            Roy Russo Master

            What are you trying to insert?

            Why didnt you use the jboss-portlet.xml, as in the reference guide?

            • 3. Re: Is header content injection coded in portal 2.4.0 ?
              Vera Mickael Newbie

               

              "roy.russo@jboss.com" wrote:
              What are you trying to insert?

              Why didnt you use the jboss-portlet.xml, as in the reference guide?


              I try to insert a css link.

              I can't use the jboss-portlet.xml as the css used is dynamically choosen.

              My application is composed of many screens, each screen uses its own css for layout and theme. We can't insert css of all screens statically in the header as they would overload each other. Each theme is an overload of a common theme.

              Mickaël

              • 4. Re: Is header content injection coded in portal 2.4.0 ?
                Vera Mickael Newbie

                This is the tag I use :

                
                public class MyHeaderContentTagHandler extends SimpleTagSupport
                {
                 public void doTag() throws JspException, IOException
                 {
                 // get page and region
                 PageContext app = (PageContext)getJspContext();
                 HttpServletRequest request = (HttpServletRequest)app.getRequest();
                
                 PageResult page = (PageResult)request.getAttribute(LayoutConstants.ATTR_PAGE);
                 JspWriter out = this.getJspContext().getOut();
                 if (page == null)
                 {
                 out.write("<p bgcolor='red'>No page to render!</p>");
                 out.write("<p bgcolor='red'>The page to render (PageResult) must be set in the request attribute '" +
                 LayoutConstants.ATTR_PAGE + "'</p>");
                 out.flush();
                 return;
                 }
                
                 Map results = page.getWindowResultMap();
                 for (Iterator i = results.keySet().iterator(); i.hasNext();)
                 {
                 String windowID = (String)i.next();
                 WindowResult result = page.getWindowResult(windowID);
                
                 // START MODIFICATION
                 Properties responseProperties = result.getResponseProperties();
                 String headerContentProperty = responseProperties.getProperty("HEADER_CONTENT");
                 if (headerContentProperty != null)
                 {
                 out.println(headerContentProperty);
                 }
                 // END MODIFICATION
                
                 if (result.getHeaderContent() != null)
                 {
                 out.println(result.getHeaderContent());
                 }
                 }
                 out.flush();
                 }
                }
                


                But I'd prefer to use the original tag.

                Mickaël

                • 5. Re: Is header content injection coded in portal 2.4.0 ?
                  Claude Keswani Newbie

                   

                  Why didnt you use the jboss-portlet.xml, as in the reference guide?

                  Hi Roy,
                  Unfortunately, declaring it in jboss-portlet.xml has some issues:
                  <header-content>
                   <script type="text/javascript" src="/my-webapp/scripts/my-script.js"></script>
                   </header-content>
                  

                  results in this:
                  <script type='text/javascript' src='/my-webapp/scripts/my-script.js'/>

                  As you can see, the closing
                  </script>

                  has been removed. This breaks html in a variety of browsers...
                  Also, according to the same doc that you reference, setting it programaticaly is alleged to be valid. And if we have to make decisions at runtime than jboss-portlet.xml is not very helpful.

                  • 6. Re: Is header content injection coded in portal 2.4.0 ?
                    Chua Khoon Yong Novice

                    hi all,

                    I'm also facing the same problem with the missing "" when injecting the headers in jboss-portlet.xml.

                    By the way, one of the sample portlet HeaderContentPortlet doesn't seem to be working for me. What i see is a blank page. This portlet is activated by clicking on "Test" in the portal navigation bar and then select "header test". This portlet has the following definition in its jboss-portlet.xml


                    <portlet-name>HeaderContentPortlet</portlet-name>
                    false
                    <header-content>



                    </header-content>



                    Any advice on this issue is most welcomed.
                    Thanks in advance.

                    • 7. Re: Is header content injection coded in portal 2.4.0 ?
                      Chua Khoon Yong Novice

                      Report :)

                      hi all,

                      I'm also facing the same problem when the

                      </script>
                      is not there during injection of the headers in jboss-portlet.xml.

                      By the way, one of the sample portlet HeaderContentPortlet doesn't seem to be working for me. What i see is a blank page. This portlet is activated by clicking on "Test" in the portal navigation bar and then select "header test". This portlet has the following definition in its jboss-portlet.xml

                       <portlet>
                       <portlet-name>HeaderContentPortlet</portlet-name>
                       <remotable>false</remotable>
                       <header-content>
                       <link rel="stylesheet" type="text/css" href="/portlet-styles/HeaderContent.css" title="" media="screen"/>
                       <script type="text/javascript" src="/portlet-styles/HeaderContent.js"/>
                       <meta name="description" content="test"/>
                       </header-content>
                       </portlet>
                      


                      Any advice on this issue is most welcomed.
                      Thanks in advance.

                      • 8. Re: Is header content injection coded in portal 2.4.0 ?
                        Viet Master

                        basically we should rather support something like :

                        <header-content>
                        <markup><![CDATA[
                         <link rel="stylesheet" type="text/css" href="@CONTEXT_PATH@/css/screen.css" title="" media="screen"/>
                         <script type="text/javascript" src="@CONTEXT_PATH@/portlet-styles/HeaderContent.js"/>
                        ]]></markup>
                        </header-content>


                        where @CONTEXT_PATH@ would be replaced by the value of the portal context path.

                        That would let more freedom in what the developer can do at the cost of maybe having invalid or conflicting markup.

                        • 9. Re: Is header content injection coded in portal 2.4.0 ?
                          Chua Khoon Yong Novice

                          hi Julien,

                          Is the markup tag currently supported in portal 2.4.1?

                          I try a few variation using the seam portal example but failed (ie. I view the html source and couldn't find that the javascript is loaded). Some variations are:

                          <header-content>
                          <markup><![CDATA[
                           <link rel="stylesheet" type="text/css" href="SeamBooking/css/screen.css" title="" media="screen"/>
                           <script type="text/javascript" src="SeamBooking/portlet-styles/HeaderContent.js"/>
                          ]]></markup>
                          </header-content>
                          


                          <header-content>
                          <markup><![CDATA[
                           <link rel="stylesheet" type="text/css" href="/SeamBooking/css/screen.css" title="" media="screen"/>
                           <script type="text/javascript" src="/SeamBooking/portlet-styles/HeaderContent.js"/>
                          ]]></markup>
                          </header-content>
                          


                          <header-content>
                          <markup><![CDATA[
                           <link rel="stylesheet" type="text/css" href="/portal/portal/default/SeamBooking/css/screen.css" title="" media="screen"/>
                           <script type="text/javascript" src="/portal/portal/default/SeamBooking/portlet-styles/HeaderContent.js"/>
                          ]]></markup>
                          </header-content>
                          



                          my setup is:

                          AS 4.0.5
                          Portal 2.4.1
                          Seam 1.1.5
                          Facelets


                          My real purpose is to incorporate AJAX4JSF, but i encountered "A4J undefined" error, and this seems to be caused by AJAX.js not loaded. Thats why i thought i could workaround it by injecting AJAX.js manually.

                          I'm lost here and your advice is most appreciated.
                          Thank you in advance.

                          • 10. Re: Is header content injection coded in portal 2.4.0 ?
                            Viet Master

                            no, it's a "we should add support for raw content"

                            • 11. Re: Is header content injection coded in portal 2.4.0 ?
                              Chua Khoon Yong Novice

                              hi julien,

                              Thanks for the information, i was behind schedule so i did a quick workaround by editing portal-themes.xml as follows:

                              <?xml version="1.0" encoding="UTF-8"?>
                              
                              <themes>
                               <theme>
                               <name>my</name>
                               <link rel="stylesheet" id="main_css" href="/themes/my/portal_style.css" type="text/css"/>
                               <link rel="shortcut icon" href="/themes/my/images/favicon.ico"/>
                               <script type="text/javascript" src="/themes/my/AJAX.js"></script>
                               </theme>
                              </themes>
                              



                              Ajax4jsf is working now, and would revisit this issue later.
                              Cheers.


                              • 12. Re: Is header content injection coded in portal 2.4.0 ?
                                Vishal Bhanderi Newbie

                                Is this true ??

                                http://jira.jboss.com/jira/browse/JBPORTAL-1246
                                http://jira.jboss.com/jira/browse/JBPORTAL-1173

                                I still cannot get the injector header to work. When i follow the manual

                                http://docs.jboss.com/jbportal/v2.6.3/referenceGuide/html_single/#d0e1851

                                Section: 6.2.3.1. My portlet just disapears as well. And I don't really understand the theme hack