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
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:
Image may be NSFW.
Clik here to view.
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:
Image may be NSFW.
Clik here to view.
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:
Image may be NSFW.
Clik here to view.
- launching it again ,the code will print the updated value:
Image may be NSFW.
Clik here to view.
Enjoy!
Tal