Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member193577
Active Contributor


Hi,

In this blog post you can find code sample of how to read properties from Portal iViews and how to set iView properties from the portal component the iView is based on.

General list of iView properties in help.sap.com

Important Note - Properties that are read and set are user personalized values. The code example bellow should be used only for this purpose.

In this example I have a Portal component called ProfileUsage and I have created an iView called myIView from it.

see more on Creating iViews

1. Reading property:


In the portal component ProfileUsage I would like to display, as output to the user, who last modified this iView.

Opening the iView in the property editor you can see the following:



For getting this in runtime the following code reads the property Id named: "com.sap.portal.pcd.unit.LastChangedBy" that holds this information and prints it to the user:

ProfileUsage.java Code:
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
response.write("This iView was last modified at:<br>");
// retrieve a property from the component profile
IPortalComponentContext componentContext = request.getComponentContext();
IPortalComponentProfile profile = componentContext.getProfile();
String lastChangedString= profile.getProperty("com.sap.portal.pcd.unit.LastChangedBy");
response.write(lastChangedString);
}



Creating iView from this Code and running the iView, the output will be:



There you have it, user administrator changed it last...

2. Having a custom property and setting property:


 

Custom properties can be added to portal components and iView through the component's PortalApp.xml file.

Here is a code sample adding a simple property to my application with the value "My property Value".

PortalApp.xml:
    <component name="ProfileUsage">
<component-config>
<property name="ClassName" value="com.sap.portal.examples.ProfileUsage"/>
</component-config>
<component-profile>
<property name="com.sap.portal.mySampleProperty" value="My property Value"/>
</component-profile>
</component>



See more on custom component properties.

Reading current value in this property and setting in through code:

ProfileUsage.java:
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
response.write("My sample property is: ");
// retrieve a property from the component profile
IPortalComponentContext componentContext = request.getComponentContext();
IPortalComponentProfile profile = componentContext.getProfile();
String myProfileProperty = profile.getProperty("com.sap.portal.mySampleProperty");
response.write(myProfileProperty);
//updating the profile property
profile.setProperty("com.sap.portal.mySampleProperty", "I've just changed this property!");
profile.store();
}



Results:

  • First launching this will print the old property:




  • launching it again ,the code will print the updated value:




Enjoy!

Tal

You want to influence the future product roadmap of Enterprise Portal? You plan to implement your portal in the Cloud? Then you should participate in the following survey https://blogs.sap.com/2016/10/11/2016-elections-vote-now/.

1 Comment