Skip to Content

Creating an iView from a deployed portal application .ear

You have created a Portal Application Project as per the document: Creating a Portal Application Project and deploying it

Now that you have built and deployed your EAR, you should create an iView, Page and Role in your portal in order to view it’s content.

To create the iView go to Content Administration -> Portal Application and copy your application.

Paste as PCD Object in your local folder under Portal Content.

Fill the required fields for the iView and then next:

In the next screen click Finish.

After you have finished you should create a role and put the iView in this role directly or through a page (must be create).

For testing only, you can right click on the iView and choose “Preview”.

The preview result:

iView’s Properties:

Every iView that we create inherits from a default template iView, therefore it inherits all the default properties (you can view an iView’s properties through portal in the property editor).
We can add our custom properties and read them within our code, in order to add a property we need to edit the “portalapp.xml” file previously mentioned.

We would add a custom property “customProp”, with the value “custom_value” of type “string”. The portalapp.xml will look as follows (the added part in marked):

<?xml version="1.0" encoding="utf-8"?>

<application>

  <application-config/>

  <components>

    <component name="MyIView">

      <component-config>

<property name="ClassName" value="com.sap.portal.somepackage.MyIView"/>

      </component-config>

      <component-profile>

      <property name="customProp" value="custom_value" type="string" />

      </component-profile>

    </component>

  </components>

  <services/>

</application>

Notice the hierarchy of the xml nodes!
In order to read the property in Runtime we should add the following lines to our code:

IPortalComponentContext componentContext = request.getComponentContext();

IPortalComponentProfile profile = componentContext.getProfile();

String value = profile.getProperty("customProp");

Note: The parameter for the getProperty() method is the property name.

For practice add to the Hello World application, code to print to screen the value of the new custom property:

The code of doContent(…) method will look as follows:

package com.sap.portal.somepackage;
import com.sapportals.portal.prt.component.*;

public class MyIView extends AbstractPortalComponent
{
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
    {
  response.write("Hello World! <br /><br />");
  IPortalComponentContext componentContext = request.getComponentContext();
  IPortalComponentProfile profile = componentContext.getProfile();
  response.write(profile.getProperty("customProp"));
    }
}

Now, build and deploy the modified EAR file as described above, and preview the result:

Tags:

No comments