Vous êtes sur la page 1sur 7

Josué Cruz.

SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)

Initial WorkSet Map for SAP Enterprise Portal

Josué Cruz (fabricadoenmexico@gmail.com)

Important Note
Is important for readers that knows that this development is based in the original Workset
Map Iview.

Objetive

The Workset Map Iview serves as entry page for a role in SAP Enterprise Portal, but there
isn´t a Initial Workset Map Iview that shows a initial portal page with information of user
roles . This is the reason to me for develop a general Initial Workset Map Iview.

My Initial Workset Map or Welcome Page looks like the image below, showing the roles
which contains the user logged into the portal. Each image is the pictogram property of each
role, and their respective role description.

Steps for making your own Initial WorkSet Map

1. Open the SAP Netweaver Developer Studio.


Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
2. Create a New Project, File > New > Project. In the wizard screen select Portal
Application > Create a Portal Application Project and click on the Next Button. Finally
enter the Project Name, “com.fabricadoenmexico.worksetmap.initialpage” and click on
the Finish Button.

3. Create a Portal ApplicationObject, File >New > Other. In the wizard screen select
Create a new Portal Application Object and click on the Next Button. Select the name
of the project created in the previous step com.fabricadoenmexico.worksetmap.initialpage and
click on the Next Button. Select Portal Component > AbstractPortalComponent and
click on the Next Button. Enter the Name and Package Name property and click on the
Finish Button.

4. Setting your classpath project. You need some JAR FILES for the project classpath.
Enter to your server and go to the path C:\USR\SAP\XXX\JXXX or /usr/sap/JXXX
(dependence of the OS). Copy the next files to some place in your local file system.
Some files can be located on the NWDS Plugins but for educational purposes i prefer
this way.

Path
../j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/WEB- INF/portal/portalapps/
Files
com.sap.portal.htmlb/lib/htmlb.jar
com.sap.portal.navigation.api_service/lib/com.sap.portal.navigation.api_service_api.jar
com.sap.portal.navigation.helperservice/lib/com.sap.portal.navigation.helperservice_api.jar
com.sap.portal.navigation..api_mimeservice/lib/ com.sap.portal.navigation.api_mimeservice_api.jar

Path
../j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/WEB- INF/portal/
Files
lib/prtapi.jar

To complete this step go to NWDS. Right Click on the name project Properties>Java
Build Path > Libaries Tab. Click on Add External JARs Button and in the new file selection
window select all the jar files that you copy to your file system in this step.

5. Open the AbstractPortalComponent. Go to open the java file


com.fabricadoenmexico.worksetmap.initialpage > src.core > InitialWorkSetMap.java

Copy the next code to this file


Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
package com.fabricadoenmexico;

import java.util.Hashtable;
import java.util.Properties;

import com.sapportals.htmlb.FormLayout;
import com.sapportals.htmlb.FormLayoutCell;
import com.sapportals.htmlb.Image;
import com.sapportals.htmlb.Link;
import com.sapportals.htmlb.TextView;
import com.sapportals.htmlb.enum.CellHAlign;
import com.sapportals.htmlb.enum.CellVAlign;
import com.sapportals.htmlb.enum.LinkDesign;
import com.sapportals.htmlb.rendering.IPageContext;
import com.sapportals.htmlb.rendering.PageContextFactory;
import com.sapportals.portal.navigation.INavigationMimeRepositoryService;
import com.sapportals.portal.navigation.INavigationNamingHandler;
import com.sapportals.portal.navigation.INavigationNode;
import com.sapportals.portal.navigation.INavigationService;
import com.sapportals.portal.navigation.NavigationEventsHelper;
import com.sapportals.portal.navigation.NavigationEventsHelperService;
import com.sapportals.portal.navigation.NavigationNodes;
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentContext;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
import com.sapportals.portal.prt.event.IPortalRequestEventData;
import com.sapportals.portal.prt.pom.INode;
import com.sapportals.portal.prt.runtime.PortalRuntime;
import com.sapportals.portal.prt.service.IService;

public class InitialWorkSetMap extends AbstractPortalComponent


{
private NavigationNodes initialNodes = null;

public void doContent(IPortalComponentRequest request, IPortalComponentResponse


response)
{
IPortalRequestEventData data = request.createRequestEventData();

//THIS METHOD LOAD THE USER NAVIGATION NODES


doLoadUser( request);

int numOfNodes = this.initialNodes.size();

INavigationNode navigationNode = null;


StringBuffer scriptTarget = null;
NavigationNodes nodes = null;

NavigationEventsHelperService service =
(NavigationEventsHelperService)
PortalRuntime.
getRuntimeResources().
getService(
"com.sap.portal.navigation.helperservice.navigation_events_helper"
);
INavigationNamingHandler navService =
(INavigationNamingHandler)
PortalRuntime.
getRuntimeResources().
getService(
"com.sap.portal.navigation.service.navigation"
);
NavigationEventsHelper helper = service.getNavigationEventsHelperInstance();
INavigationMimeRepositoryService mimeRepositoryService =
(INavigationMimeRepositoryService)
PortalRuntime.
getRuntimeResources().
getService(
"com.sap.portal.navigation.mimeservice.navigation_mime_repository"
);

String mimeServiceCompName =
((IService)mimeRepositoryService).getContext().getApplicationName();
String webResource = request.getWebResourcePath(mimeServiceCompName);
IPortalComponentContext componentContext = request.getComponentContext();
Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
navigationNode = service.getCurrentLaunchNavNode(request);

String navCompName = navigationNode.getName();


navCompName = service.getInternalURL(navCompName);

String parentName = null;


if(request.getComponentContext() != null){
parentName = request.getComponentContext().getContextName();
parentName = service.getInternalURL(parentName);
}

INode currentNode = request.getNode();


request.setNode(request.getNode().getParentNode());
request.setNode(currentNode);
response.write("<SCRIPT>");
response.write("function openURL(eventObj) {");
response.write("EPCM.doNavigate(eventObj); ");
response.write("}");
response.write("</SCRIPT>");

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


com.sapportals.htmlb.Form myForm =
myContext.createFormDocument("overviewCompName");

myContext.getDocument().addComponent(myForm);
FormLayout matrixLayout = new FormLayout();
FormLayout worksetEntryLayout = new FormLayout();
FormLayoutCell cell = null;
FormLayoutCell imageCell = null;
FormLayoutCell titleCell = null;
FormLayoutCell descCell = null;

com.sapportals.htmlb.ClientEventContainer eventContainer = null;


TextView descTextView = null;
INavigationNode currNode = null;
Link titleLink = null;
int currentPageLocation = -1;
int k = 1;

//THE NEXT CODE LINE IS IMPORTANT, IS THE COLUMN NUMBERS IF YOU WANT MORE THAN 2
int middlePoint = numOfNodes % 2 != 0 ? numOfNodes / 2 + 1 : numOfNodes / 2;

int i = 0;

for(int j = 1; i < numOfNodes; j++) {


currNode = (INavigationNode)this.initialNodes.get(i);
if(currNode.getName().endsWith(navCompName) ||
parentName != null &&
currNode.getName().endsWith(parentName))
{
currentPageLocation = j;
break;
}
i++;
}

if(currentPageLocation != -1 && numOfNodes % 2 == 1)


middlePoint--;

i = 0;
try
{
//IF YOU WANT TO PRNT THE FIRST NAVIGATION PUT TO TRUE PRINTFIRSTNODE
String printFirstNode = "false";
int initialIndex = 1;
if (printFirstNode.equalsIgnoreCase("false") && 2 < numOfNodes)
i++;

for(int j = 1 ; i < numOfNodes; j++)


{
INavigationNode node = (INavigationNode)this.initialNodes.get(i);
currNode = (INavigationNode)node;

if( j == currentPageLocation || k == 3 &&


middlePoint + j == currentPageLocation)
{
j--;
Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
currentPageLocation = -1;
} else {
if(j > middlePoint) {
j = 1;
k++;
}
worksetEntryLayout = new FormLayout();
boolean enablePictogramClick = false;
Image image = null;
String enablePicClickProperty = "false";

if(enablePicClickProperty != null)

enablePictogramClick = Boolean.valueOf(
enablePicClickProperty).booleanValue()
);
String imageName = null;
try
{
imageName = (String)currNode.getAttributeValue(
"com.sapportals.portal.navigation.Pictogram"
);
if(imageName == null || imageName.equals(""))
imageName = "default.gif";
} catch(Exception e){
imageName = "default.gif";
}
image = new Image(webResource + "/images/" + imageName, imageName);

if(enablePictogramClick)
{
String nameImgLink = currNode.getName() + "imageLinkToNode";

Link imageLink = new Link(nameImgLink, "");


scriptTarget = new StringBuffer();
String navContext = null;

navContext = currNode.getName();
helper.addClickEvent(currNode,
scriptTarget,
request,
false,
"ExecuteLocally=true", navContext
);
imageLink.setReference("javascript:void(0)");
imageLink.setOnClientClick(scriptTarget.toString());
imageLink.setLinkDesign(LinkDesign.DRAGRELATE);
imageLink.addComponent(image);
imageCell = worksetEntryLayout.addComponent(1, 1, mageLink);
} else {
imageCell = worksetEntryLayout.addComponent(1, 1, image);
}
imageCell.setRowspan(2);
imageCell.setPaddingRight("25");
imageCell.setPaddingLeft("5");
imageCell.setVerticalAlignment(CellVAlign.TOP);
try
{
titleLink = new Link(currNode.getName(),
currNode.getTitle(request.getLocale()));
scriptTarget = new StringBuffer();
helper.addClickEvent(currNode,
scriptTarget,
request,
false,
true,
"ExecuteLocally=true",
true
);
titleLink.setReference("javascript:void(0)");
titleLink.setOnClientClick(scriptTarget.toString());
titleLink.setLinkDesign(LinkDesign.DRAGRELATE) ;
titleLink.setTooltip(currNode.getTitle(request.getLocale()));
descTextView = new TextView(
currNode.getDescription(request.getLocale())
);
Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
descTextView.setWrapping(true);
titleCell = worksetEntryLayout.addComponent(1, 2, titleLink);
descCell = worksetEntryLayout.addComponent(2, 1, descTextView);
titleCell.setVerticalAlignment(CellVAlign.TOP);
titleCell.setHorizontalAlignment(CellHAlign.LEFT);
descCell.setVerticalAlignment(CellVAlign.TOP);
descCell.setHorizontalAlignment(CellHAlign.LEFT);
descCell.setWidth("100%");
} catch(Exception e) {
descCell = worksetEntryLayout.addComponent(2, 1, new TextView());
}
worksetEntryLayout.setWidth("100%");
worksetEntryLayout.setDebugMode(false);
cell = matrixLayout.addComponent(j, k, worksetEntryLayout);
cell.setPaddingLeft("5");
cell.setPaddingTop("5");
cell.setPaddingRight("25");
cell.setPaddingBottom("5");
cell.setVerticalAlignment(CellVAlign.TOP);
}
i++;
}
} catch (Exception e) {
e.printStackTrace();
}
matrixLayout.setWidth("80%");
matrixLayout.setDebugMode(false);
myForm.addComponent(matrixLayout);
myContext.render();
}

public int doLoadUser(IPortalComponentRequest request){


Hashtable environment = new Hashtable();
environment.put("NavigationPrincipal", request.getUser());
INavigationService connector = (INavigationService)
PortalRuntime.
getRuntimeResources().
getService(
"com.sap.portal.navigation.service.navigation"
);
try
{
this.initialNodes = connector.getInitialNodes(environment);
}catch (Exception e)
{
}
return 0;
}
}

6. Edit the portalapp.xml. Go to project name and navigate to


com.fabricadoenmexico.worksetmap.intialpage > dist > PORTAL-INF >portalapp.xml
right click on this file and click on Open With > Portalapp.xml Editor, choose Source Tab
and copy this xml lines.
<?xml version="1.0" encoding="UTF-8"?>
<application>
<application-config>
<property name="SharingReference"
value="usermanagement,knowledgemanagement,com.sap.portal.navigat
ion.service, com.sap.portal.navigation.api_mimeservice,
com.sap.portal.navigation.helperservice"/>
<property name="PrivateSharingReference"
value="com.sap.portal.htmlb"/>
<property name="releasable" value="true"/>
</application-config>
<components>
<component name="InitialWorkSetMap">
<component-config>
Josué Cruz. SAP Portal, SAP KM, SAP Java Developer, SAP ESS/MSS, SAP Internet Sales, ABAP
certified, Adobe Forms (fabricadoenmexico@gmail.com)
<property name="ClassName"
value="com.fabricadoenmexico.InitialWorkSetMap"/>
</component-config>
<component-profile/>
</component>
</components>
<services/>
</application>

7. Create the PAR file. Right click on <project_name> and Quick PAR Upload option. In
the wizard click on Finish Button.
8. Upload the PAR file. Enter like Administrator to SAP Portal and go to System
Administration > Support > Portal Runtime > Administration Console. Select the PAR
file you made in the last step and click on the Upload button.
9. Create an iview of type Portal Component. Obviously your component you have
created.
10. Create a role.
11. Assign the iview to role.
12. Assign the role to a user.
13. Enter to test.

If you ok then
You = 
Endif

Vous aimerez peut-être aussi