Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to include a CSS from another project

Hi all,

I'm developing an AbstractPortalComponent which uses some of my own defined stylesheets. I can include the stylesheet defined in my own project by this:

com.sapportals.portal.prt.resource.IResource myStyle = 
request.getResource("css", "css/my_nav.css");    
response.include(request, myStyle);

Now I need to include another CSS but from another project.

I tried also to get the response and write the HTML code but it writes it into the <BODY></BODY> tag and the CSS is not used when rendering the document:

...</head>
<body class="prtlBody urFontBaseFam urScrl">
<LINK REL=stylesheet HREF="/irj/portalapps/myProject/css/zglobal.css" TYPE="text/css">
...

Does anybody know the solution?

Thanks in advance,

Romano

replied

There are document hooks that you can use to insert things into the response of a page being written to the client.

Therefore, if you create a service which implements the IDocumentHookListener, you will then need to implement the

String doDocumentHook(int documentPosition, IPortalComponentRequest request, IPortalComponentResponse response)

and

void doDocumentHook(int documentPosition, IPortalComponentRequest request, IPortalComponentResponse response)

The first method, that returns a String, you can basically check where in the document you would like to write code, something like

switch (documentPosition) {
  case IDocumentHookListener.HEAD_SECTION_BEGIN :
    return "some string";
    break;
  case IDocumentHookListener.HEAD_SECTION_END :
    return "some other string";
    break;
}

The second method, simply writes out the String returned from the first method to the response, i.e.

  response.write(doDocumentHook(documentPosition, request));

I hope this helps

Darrell

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question