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:

/wp-content/uploads/2014/07/1111_491533.png

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:

/wp-content/uploads/2014/07/1111_491533.png

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:

/wp-content/uploads/2014/07/1111_491533.png

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

/wp-content/uploads/2014/07/2222_491561.png

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/.

To report this post you need to login first.

1 Comment

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

  1. Jaspreet Verma

    Hi,

    This is well explained note but l’m having a few queries:

    1.How the code will fetch exactly the property of myiview as there can be another iviews present in portal content.you have not mentioned the path of iview.

    2.Will this code work in sap NW 7.3?

    3.What all jarfiles required for this code?

    4.Is is possible to set property of iview at particular interval of time?If yes please tell how

     

    (0) 

Leave a Reply