> On Wed, Jan 26, 2011 at 4:38 PM, anyz <[email protected]> wrote:
>
>> Its could be more portlet specific question but i think every portlet
>> platform might be providing its own way.
>>
>> Since we don't have control over <head> tag in portlet JSP page. How can i
>> import a css/js file required for a portlet in fragment JSP in Jetspeed.
>> There could be multiple portlets that uses same or differnt CSS and
>> Javascript files, how can we make sure a resource (css or js) is included
>> exactly once.
Jetspeed has had support for this for a long while. The Portlet 2.0
API introduced the doHeaders method to generic portlet (1). You can
look at some of the Jetspeed administrative portlets for examples such
as JetspeedToolbox.java:
@Override
protected void doHeaders(RenderRequest request, RenderResponse response) {
super.doHeaders(request, response);
RequestContext rc = (RequestContext)
request.getAttribute(RequestContext.REQUEST_PORTALENV);
Element headElem = response.createElement("script");
headElem.setAttribute("language", "javascript");
String scriptPath = rc.getRequest().getContextPath() + yuiScriptPath;
headElem.setAttribute("id",
HeaderPhaseSupportConstants.HEAD_ELEMENT_CONTRIBUTION_ELEMENT_ID_YUI_LIBRARY_INCLUDE);
headElem.setAttribute("src", scriptPath);
headElem.setAttribute("type", "text/javascript");
response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
}
(1)
http://www.bluesunrise.com/portlet-api/javax/portlet/GenericPortlet.html#doHeaders%28javax.portlet.RenderRequest,%20javax.portlet.RenderResponse%29
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]