Show TOC

Background documentationObject References Locate this document in the navigation structure

 

The following table shows how to access components, services and resources in the current application or in another application.

Object

How to Reference

Component

A component can reference another component by retrieving an IPortalComponentContext object for the component from the IPortalComponentRequest object, as in the following example:

request.getComponentContext("myApplication.myComp");

The above example gets a reference to the myComp component defined in the myApp application. You can use the object, for example, to add a component to the POM tree, or to get information and resources from the component.

Service

A component or service can reference a service by retrieving an IService object for the service. The IService object can then be cast into the interface for the corresponding service.

PortalRuntime.getRuntimeResources().getService( ITransformerService.KEY);

The above example gets a reference to the transformation service. PortalRuntime is a member of the com.sapportals.portal.prt.runtime package.

Resource

A component can reference a Web resource packaged in its application or in another application by retrieving an IResource object for the resource from the IPortalComponentRequest object, as in the following examples:

  • For a resource in the same application:

    request.getResource(IResource.IMAGE,"images/myImage.gif");

  • For a resource in another application:

    request.getResource ("myApp",IResource.IMAGE,"images/myImage.gif");

A component can use a Web resource, for example, to create a link to the resource or to include it in its content.

Property (component)

A component can reference one of its profile properties, which are defined in <property> elements in the <component-profile> element in the component's deployment descriptor.

You can also access properties defined by the semantic object in which the component is running. For example, if the component is run as an iView, the iView semantic object defines properties, such as com.sap.portal.pcm.Title for the iView's name.

The property value is first defined in the deployment descriptor, and then can be modified by an administrator for the specific iView, and then can be modified by the current user if the property is defined as personalizable.

The following retrieves the value of myProperty:

IPortalComponentProfile profile = request.getComponentContext().getProfile(); String propertyValue = profile.getProperty("myProperty");

The properties defined in the <component-config> element cannot be referenced.

Property (service)

A service can reference one of its profile properties, which are defined in <property> elements in the <service-profile> element in the component's deployment descriptor, within the service's init() method.

The init() method is passed a IServiceContext object, which you can use as follows to retrieve a property value:.

String propertyValue = serviceContext.getServiceProfile().getProperty("myProperty");

Referencing Other Applications

To access components and services defined in another application, your application must reference the other application in a <property> element of the <application-config> element of its deployment descriptor.

For example, the following enables your application to make use of components and services in the portal application called com.sap.myApp:

Syntax Syntax

  1. <property name="SharingReference" value="com.sap.myApp"/>
End of the code.

The above reference is required in order to access components or services in com.sap.myApp, but not required for accessing the application's resources. For more information about <property> elements in the <application-config> element of the deployment descriptor, see Application Configuration.