Search This Blog

Wednesday, November 10, 2010

How to access page parameters from a Portal Theme

Agenda : How to access the custom page parameters from IBM Theme.

When editing a portal page, you can add custom page parameters (metadata) to the page. The value of a custom page parameter can then be retrieved from your WPS theme code. This explains how.

First, you must add a custom parameter to one or more portal pages. This is done in the Edit Page view > Advanced options > I want to set parameters.

You can then access the named parameters in your theme code.

Take the following parameter name for example:

Name     : com.acme.page.hidden

Value      :true

Following is an example where this technique is used to determine whether or not a tab for a portal page should be rendered in the UI. This is taken from a theme file called topNav.jspf.


////////////////////////////////////////////////
<portal-navigation:navigationLoop>
     <%

    boolean isPageHidden = false;

    ContentNodeType nodeType = wpsNavNode.getContentNode().getContentNodeType();

    if (wpsNavNode instanceof com.ibm.portal.MetaDataProvider) {
            com.ibm.portal.MetaData iMetaData = ((com.ibm.portal.MetaDataProvider) wpsNavNode).getMetaData();              
            Object hiddenValue = iMetaData.getValue("com.acme.page.hidden");
            if (hiddenValue != null && hiddenValue.toString().equalsIgnoreCase("true") ){
                    isPageHidden = true;
            }
    }
    if (!isPageHidden) {
     %>

        ... OTHER JSP CODE GOES HERE...

    <% } // end isPageHidden %>
</portal-navigation:navigationLoop>


//////////////////////////////////

Note: To access the custom unique name for the page, try this using the same wpsNavNode object
that is shown as available within the portal-navigation loop above:

<%= wpsNavNode.getContentNode().getObjectID().getUniqueName() %>

1 comment:

  1. This way i'm not able to get inherited page parameters, do you have any suggestions for that?

    ReplyDelete