Skip to Content

MOTIVATION

By default, the portal does not support the standards rendering mode and renders all content in quirks mode.

In order to add this support to the portal, a new capability was added which enables proper display of content rendered in standards mode. A new navigation mode (NAV MODE 10) has been exposed which allows running content in a headerless framework page which opens in standards mode rendering and displays HTML5 content properly.

This blog is about giving a best practice for switching desktops in runtime to run in one desktop quirks content and in other desktop html5 content. Of course you can use it for other use cases.

The idea is to write a dropdown in the masthead presenting all available desktops names and when a user selects one, the current desktop switches accordingly to the chosen desktop.

That way, users can watch content rendered in quirks mode, and then switch to watch content that is rendered in standards mode.

Also, you can achieve easy switching between desktops with content rendered in different modes using desktop filter, which will filter the user’s desktops and separate those rendered in standards mode and quirks mode.

DETAILED EXPLANATION

1.       Write a portal application as described below.

2.       Deploy it into the portal.

3.       Create an iView based on the application.

4.       Go to Portal Content -> Portal Users -> Standard Portal Users.

5.       Choose a framework page you would wish to add the iView to.

step5.PNG

6.       Add the iView to the page (it will automatically be added to the Masthead Container).

step6good.PNG

7.       The final result:

step7.PNG

Choose a desktop:

step7a.PNG

Click on it:

step7b.PNG

*** If your request is to reach any desktop from any other desktop, you must create this iView in each one of the desktops.

SOURCE CODE

Creating a portal component:

Includes creating a Dropdown Listbox which contains all the desktops available for this specific user, Event handeling when the user chooses a desktop at runtime, and changing the desktop to the one chosen: 

public class HTMLBdropdown extends AbstractPortalComponent

{

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

IPageContext context = PageContextFactory.createPageContext(request, response);

IUser user = request.getUser();

String[] desktops = getDesktops(user);

response.write(“Please choose a desktop:”);

createDropdownListBox(context, desktops);

ProcessEvent(“proc_listbox”, request, response, context);

}

private void ProcessEvent(String event, IPortalComponentRequest request, IPortalComponentResponse response, IPageContext context)

{

Event evnt = context.getCurrentEvent();

if (evnt != null)

{

if (event.equals(“proc_listbox”))

{

DropdownListBox dropdownlist = (DropdownListBox)context.getComponentForId(“dropdown”);

String selected = dropdownlist.getSelection();

setDesktop(selected, request, response);

}

}

}

private String[] getDesktops(IUser user)

{

IDesktopService desktopService = (IDesktopService)PortalRuntime.getRuntimeResources().getService(IDesktopService.KEY);

String[] desktops = null ;

try

{

desktops = desktopService.searchDesktopUrls(user);

}

catch(NamingException e)

{

}

return desktops;

}

private void createDropdownListBox(IPageContext cntx, String[] desktops)

{

Form form = cntx.createFormDocument(“form_id”);

Document doc = cntx.createDocument(“doc_id”);

DropdownListBox dropdown = new DropdownListBox(“dropdown”);

dropdown.setTooltip(“Select an item”);

dropdown.setWidth(“1000”);

dropdown.setOnSelect(“proc_listbox”);

dropdown.addItem(“”, “”);

for (int numOfDesktops=0; numOfDesktops<desktops.length; numOfDesktops++){

dropdown.addItem(desktops[numOfDesktops],desktops[numOfDesktops]) ;

}

form.addComponent(dropdown);

doc.addComponent(form);

doc.render(cntx);

}

private void setDesktop(String selected, IPortalComponentRequest request, IPortalComponentResponse response)

{

IAliasHelper aliasHelper = (IAliasHelper)PortalRuntime.getRuntimeResources().getService(“com.sap.portal.navigation.AliasService.AliasService”);

String portalAlias=””;

portalAlias = aliasHelper.getPath(request);

String newUrl = portalAlias+”?”;

IDesktopService desktopservice = (IDesktopService) PortalRuntime.getRuntimeResources().getService(IDesktopService.KEY);

desktopservice.setRuntimeDesktop(selected,request);

response.write(“<script>\n”);

response.write(“location.replace(\”” + newUrl + “\”);\n”);

response.write(“</script>\n”);

String noscript = “<noscript>\n”;

noscript = noscript + “If you are not redirected automatically please click here: <a href=\”” + newUrl + “\”>Switch to new market.</a>\n”;

noscript = noscript + “</noscript>\n”;

response.write(noscript);

}

}

EXPLANATION OF THE SOURCE CODE

1. Creating a page context for generating output:

Create an instance of HTMLB IPageContext with the request and response of the portal component in order to later create a Form and a Document which will hold the dropdown listbox.

2. Receiving the user’s desktops

Retrieve the user through the request made, and then with the help of IDesktopService receiving the URLs of the user’s desktops.

3. Creating a dropdown listbox

Create a Form and a Document as part of the IPageContext. Then create a new instance of HTMLB Dropdown ListBox and set it’s attributes according to the control API. Once it is created and has all the attributes needed, add items to the list (using the addItem(String key, String value) method). Add the dropdown listbox you’ve created as the Form’s component, the Form as the Document’s component, and render the Document with the IPageContext that was created.

4. Processing the event

Receive an event using the IPageContext and check if the current event equals the onSelect event that was defined. If it is, retrieve the selection that was made by the user and set the desktop accordingly. In order to switch to the chosen desktop, use the IAliasHelper and the IDesktopService services. Set the runtime desktop, and write an HTML script attribute which performs “location.replace(newUrl)” to the response.

And keep working on your new desktop…!

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply