You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by anyz <an...@gmail.com> on 2011/01/26 12:38:16 UTC

How to link custom css/js in portlet fragment

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.

Thanks

Re: How to link custom css/js in portlet fragment

Posted by David Taylor <da...@gmail.com>.
> On Wed, Jan 26, 2011 at 4:38 PM, anyz <an...@gmail.com> 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: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: How to link custom css/js in portlet fragment

Posted by anyz <an...@gmail.com>.
Thanks and lot David and Woonsan, seems exactly what i need. I will be
looking further on these lines and add custom css and scritps.

Re: How to link custom css/js in portlet fragment

Posted by Woonsan Ko <wo...@yahoo.com>.
You can add custom head elements from your portlet code since Jetspeed-2.2.1 supports the feature, "PLT.12.5.4 Setting Markup Head Elements", defined in the Portlet Specification.
Basically, you can use the following to create and contribute your head element:
- javax.portlet.PortletResponse#createElement(tagName);
- javax.portlet.PortletResponse#addProperty(javax.portlet.MimeResponse.MARKUP_HEAD_ELEMENT, elem);
- It is recommended to override javax.portlet.GenericPortlet#doHeaders(req, res) to contribute your head elements.

For example, you can create a css or script tag element and contribute it to portal page. Jetspeed-2 portal will include your contributed elements properly.

One extensional behavior is that Jetspeed-2 portal keeps the first contributed head element only if there's duplicate head element contributions from other portlets.

If a contributed head element has an (case-insensitive) ID attribute (e.g., id='democss'), then Jetspeed-2 portal will regard the id attribute as an identifier. If there's another head element contribution from other portlet with same id attribute value, then that head element with the same id will be just ignored.

If contributed head elements don't have ID attributes, then the stringified expression of the head element will be used to compare. If there's anything different in attributes, text or order, those will be treated as different head elements.

By the way, the demo.css in demo PA doesn't seem to be related to this context. It seems like an old dojo example.


HTH,

Woonsan


--- On Wed, 1/26/11, anyz <an...@gmail.com> wrote:

> From: anyz <an...@gmail.com>
> Subject: Re: How to link custom css/js in portlet fragment
> To: "Jetspeed Users List" <je...@portals.apache.org>
> Date: Wednesday, January 26, 2011, 12:52 PM
> Just to elaborate a bit, there is
> demo.css in demo webapplication shipped
> with J2 (2.2.1). I could not find where this css file is
> imported in JSP
> pages for portlets in this application. That is exactly
> what i need to do.
> 
> 
> 
> 
> On Wed, Jan 26, 2011 at 4:38 PM, anyz <an...@gmail.com>
> 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.
> >
> > Thanks
> >
> >
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: How to link custom css/js in portlet fragment

Posted by anyz <an...@gmail.com>.
Just to elaborate a bit, there is demo.css in demo webapplication shipped
with J2 (2.2.1). I could not find where this css file is imported in JSP
pages for portlets in this application. That is exactly what i need to do.




On Wed, Jan 26, 2011 at 4:38 PM, anyz <an...@gmail.com> 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.
>
> Thanks
>
>