Adding meta tag to head element of JSR 286 portlet in Webspehere portal

1k Views Asked by At

We have developed JSR 286 portlet. While loading the JSP page in IE8, we are facing some alignment issues due to which our screen is not loading properly.

We could figure out that, it is because of the IE 8 compatibility issue. By default the page loads in Quirks mode in IE8. If we change the mode to IE8 Standard, we are able to see the page loading without any issue. I could find that we can set a meta <meta http-equiv='X-UA-Compatible' content='IE=EmulateIE8' />" for enabling the IE8 standard mode from the JSP.

But how can I add the meta tag into the head element of the portlet page? Since I dont have the <html>, <head> and <body> tags in my web application and it will be generated from the portlet container, how can I add the meta tag to the head element?

I tried overriding the doHeader method also as follows

protected void doHeaders(RenderRequest request, RenderResponse response) {
    Element metaKeywords = response.createElement("meta");
    metaKeywords.setAttribute("http-equiv", "X-UA-Compatible");
    metaKeywords.setAttribute("content", "IE=EmulateIE8");
    // response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, ""); - I tried this option   also
   //response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, metaKeywords); - I tried this option also
}

But nothing worked out.

Our application is running on WAS 7.0.

Can anyone give some pointers ?

1

There are 1 best solutions below

0
On

Ok, this is not going to be useful to the OP anymore, but here is the answer.

One can can do it at the "render lifecycle phase" of the portlet — in more mundane terms, one can do it by overriding GenericPortlet.doHeaders():

public class MyPortlet extends GenericPortlet {

    @Override
    public void doHeaders(RenderRequest req, RenderResponse res)
    throws PortletException {
        Element meta = response.createElement("meta");

        meta.setAttribute("http-equiv", "X-UA-Compatible");
        meta.setAttribute("content", "IE=EmulateIE8");

        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, meta);
    }
}

You may have to set a container runtime option on your portlet.xml if your portal is a streaming portal:

<portlet>
    <container-runtime-option>
        <name>javax.portlet.renderHeaders</name>
        <value>true</value>
    </container-runtime-option>
</portlet>

(More about streaming vs. buffering portals, and a good code example, here.)

Also, note the portal is free to ignore your element if it considers it to be a security risk, but I did not have problems with that until now.

I have not tested this specific code, but have did something similar (on Pluto at least) and it worked. So, those can be good starting points.

NOTE: JSR-362 (Portlet 3.0) will have an entire portlet lifecycle phase for that, HEADER_PHASE. In this case, one just needs to implement renderHeaders(HeaderRequest, HeaderResponse). But this spec is a draft yet.