Sun Java System Portal Server 7 Developer's Guide

Example 2: Developing SpanTableContainerProvider

The sample SpanTableContainerProvider provides a layout for a Thin_Wide_Thin_Span column. This table Desktop layout has three columns with the full_bottom spanning two (left and center) columns.

ProcedureTo Develop the SpanTableContainerProvider

Steps
  1. Extend JSPTableContainerProvider and develop the SpanTableContainerProvider class file.

    The SpanTableContainerProvider class is implemented by extending the JSPTableContainerProvider class as shown below.

    SpanTableContainerProvider.java File


    package custom;
    
    import com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider;
    import com.sun.portal.providers.ProviderException;
    import com.sun.portal.providers.ProviderWidths;
    import com.sun.portal.providers.Provider;
    
    import com.sun.portal.providers.context.ContainerProviderContext;
    
    import javax.servlet.http.HttpServletRequest;
    
    import java.util.List;
    
    public class SpanTableContainerProvider extends JSPTableContainerProvider {
        public int getRowSpan(HttpServletRequest req) throws ProviderException {
            int rowSpan = 1;
            List selected = getSelectedChannels();
            for (int i=0; i < selected.size(); i++) {
                String channel = (String)selected.get(i);
                Provider p = getContainerProviderContext().getProvider(req, getName(), channel);
    
                if ( (p.getWidth() == ProviderWidths.WIDTH_FULL_BOTTOM) ) {
                    rowSpan = rowSpan++;
                }
            }
            return rowSpan;
        }
    }
  2. Compile the class and put it in the provider class base directory.

    The default directory for the class file is PortalServer-DataDir/portals/portal-ID/desktop/classes. That is, build the JAR and copy the JAR into the provider class base directory. Or, just copy the class as a file into the provider class base directory. To compile the SpanTableContainerProvider.java file, enter:


    javac -d PortalServer-DataDir/portals/portal-ID/desktop/classes -classpath PortalServer-base/sdk/desktop/desktopsdk.jar:AccessManager-base/lib/servlet.jar SpanTableContainerProvider.java
  3. Develop the display profile XML fragments for this provider and this provider’s channel.

    The display profile fragment for SpanTableContainerProvider’s provider is saved in SpanTCProvider.xml file and the display profile fragment for SpanTableContainerProvider’s channel is saved in SpanTCChannel.xml file.

    SpanTCProvider.xml File


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    
    <Provider name="SpanTableContainerProvider" class="custom.SpanTableContainerProvider">
        <Properties>
            <String name="contentPage" value="toptable.jsp"/>
            <Integer name="timeout" value ="1800"/>
            <Integer name="layout" value="1"/>
            <Boolean name="showExceptions" value="false"/>
            <Boolean name="parallelChannelsInit" value="false"/>
            <String name="title" value="Table Container Provider"/>
            <String name="description" value="DESCRIPTION"/>
            <String name="refreshTime" value="0"/>
            <String name="width" value="thin"/>
            <String name="fontFace1" value="Sans-serif"/>
            <String name="Desktop-fontFace1" value="Sans-serif"/>
            <String name="productName" value="Sun Java System Portal Server"/>
            <String name="presetThemeChannel" value="JSPPresetThemeContainer"/>
            <String name="customThemeChannel" value="JSPCustomThemeContainer"/>
            <Boolean name="refreshParentContainerOnly" value="false" advanced="true"/>
            <Boolean name="isEditable" value="true"/>
            <String name="editType" value="edit_complete"/>
            <String name="editContainerName" value="JSPEditChannel"/>
            <Integer name="thin_popup_height" value="200"/>
            <Integer name="thin_popup_width" value="500"/>
            <Integer name="thick_popup_height" value="300"/>
            <Integer name="thick_popup_width" value="600"/>
            <Integer name="fullwidth_popup_height" value="500"/>
            <Integer name="fullwidth_popup_width" value="600"/>
            <Collection name="categories">
                <String value="Personal Channels"/>
                <String value="Sample Channels"/>
                <String value="News Channels"/>
                <String value="Search Channels"/>
            </Collection>
            <Collection name="Personal Channels">
                <String value="UserInfo"/>
                <String value="MailCheck"/>
                <String value="Bookmark"/>
                <String value="App"/>
            </Collection>
            <Collection name="Sample Channels">
                <String value="SampleSimpleWebService"/>
                <String value="SampleJSP"/>
                <String value="SampleXML"/>
                <String value="SampleURLScraper"/>
            </Collection>
            <Collection name="News Channels">
                <String value="SampleRSS"/>
                <String value="Postit"/>
            </Collection>
            <Collection name="Search Channels">
                <String value="Search"/>
            </Collection>
            <Boolean name="defaultChannelIsMinimizable" value="true"/>
            <Boolean name="defaultChannelIsMinimized" value="false" advanced="true"/>
            <Boolean name="defaultChannelIsDetached" value="false" advanced="true"/>
            <Boolean name="defaultChannelIsDetachable" value="true"/>
            <Boolean name="defaultChannelIsRemovable" value="true"/>
            <Boolean name="defaultChannelHasFrame" value="true" advanced="true"/>
            <Boolean name="defaultChannelIsMovable" value="true"/>
            <Boolean name="defaultBorderlessChannel" value="false" advanced="true"/>
            <String name="defaultChannelColumn" value="1" advanced="true"/>
            <String name="defaultChannelRow" value="1" advanced="true"/>
            <Collection name="channelsIsMinimized" advanced="true"/>
            <Collection name="channelsIsDetached" advanced="true"/>
            <Collection name="channelsHasFrame" advanced="true"/>
            <Collection name="channelsIsMinimizable"/>
            <Collection name="channelsRow" advanced="true"/>
            <Collection name="channelsColumn" advanced="true"/>
            <Collection name="channelsIsMovable"/>
            <Collection name="channelsIsDetachable"/>
            <Collection name="channelsIsRemovable"/>
            <Collection name="borderlessChannels"/>
        </Properties>
    </Provider>

    SpanTCChannel.xml File


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    
    <Container name="SpanTableContainerChannel" provider="SpanTableContainerProvider">
        <Properties>
            <String name="title" value="Front Table Container Channel"/>
            <String name="contentPage" value="toptable.jsp"/>
            <String name="description" value="This is a test for spanning table containers" />
            <String name="Desktop-fontFace1" value="Sans-serif"/>
            <Collection name="categories">
                <String value="Personal Channels"/>
                <String value="Sample Channels"/>
                <String value="News Channels"/>
            </Collection>
            <Collection name="Personal Channels">
                <String value="UserInfo"/>
                <String value="MailCheck"/>
                <String value="Bookmark"/>
                <String value="App"/>
            </Collection>
            <Collection name="Sample Channels">
                <String value="SampleJSP"/>
                <String value="SampleXML"/>
            </Collection>
            <Collection name="News Channels">
                <String value="SampleRSS"/>
            </Collection>
            <Collection name="channelsRow" advanced="true">
                <String name="MailCheck" value="4"/>
                <String name="App" value="5"/>
                <String name="Bookmark" value="3"/>
                <String name="SampleRSS" value="2"/>
                <String name="SampleXML" value="2"/>
            </Collection>
            <Collection name="channelsIsRemovable" >
                <Boolean name="UserInfo" value="false"/>
            </Collection>
            <Collection name="amList">
                <String value="UserInfo"/>
                <String value="MailCheck"/>
                <String value="App"/>
                <String value="Bookmark"/>
            </Collection>
            <Collection name="pmList">
                <String value="MyFrontPageTabPanelContainer/Bookmark2"/>
                <String value="MailCheck"/>
                <String value="SampleXML"/>
                <String value="SampleRSS"/>
            </Collection>
        </Properties>
        <Available>
            <Reference value="UserInfo"/>
            <Reference value="MailCheck"/>
            <Reference value="App"/>
            <Reference value="Bookmark"/>
            <Reference value="MyFrontPageTabPanelContainer/Bookmark2"/>
            <Reference value="SampleJSP"/>
            <Reference value="SampleRSS"/>
            <Reference value="SampleXML"/>
        </Available>
        <Selected>
            <Reference value="UserInfo"/>
            <Reference value="MailCheck"/>
            <Reference value="App"/>
            <Reference value="Bookmark"/>
            <Reference value="MyFrontPageTabPanelContainer/Bookmark2"/>
            <Reference value="SampleJSP"/>
            <Reference value="SampleRSS"/>
            <Reference value="SampleXML"/>
        </Selected>
        <Channels>
        </Channels>
    </Container>
  4. Use the psadmin command to upload the display profile fragments for this provider.

    For SpanTableContainerProvider, use the psadmin add-display-profile subcommand to upload the CustomTCProvider.xml file and CustomTCChannel.xml file fragments in the display profile. See the Sun Java System Portal Server 7 Command-Line Reference for more information on this subcommand.

  5. Create a new directory for the provider in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory. The directory for the provider is typically named after the channel.

    For the sample SpanTableContainerProvider, create a directory called SpanTableContainerChannel in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory.

  6. Copy files from PortalServer-DataDir/portals/portal-ID/desktop/default/JSPTableContainerProvider to the newly created directory.

  7. Modify the JSP files (in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/SpanTableContainerChannel) as shown in Step a, Step b, and Step c (modifications to the file are shown in bold):

    1. Add the following to toptable.jsp file:


      <!-- BEGIN FULL TOP CHANNELS -->
      <dttable:getColumns id="channels" column="top" scope="request"/>
      <jsp:include page="tabletopbottom.jsp" flush="true">
      <jsp:param name="columnName" value="top"/>
      </jsp:include>
      <!-- END TOP CHANNELS -->
      <!-- BEGIN FULL BOTTOM CHANNELS -->
      <dttable:getColumns id="channels" column="bottom" scope="request"/>
      <jsp:include page="tabletopbottom.jsp" flush="true">
      <jsp:param name="columnName" value="bottom"/>
      </jsp:include>
      <!-- END BOTTOM CHANNELS -->

      Here, tcp is an instance of SpanTableContainerProvider.

    2. Add the following to tablecolumn.jsp file:


      <%@ page import="custom.SpanTableContainerProvider"%>
      <%@ page session="false" %>
      <% SpanTableContainerProvider tcp = (SpanTableContainerProvider)pageContext.getAttribute("JSPProvider"); %>
      <dt:obtainContainer container="$JSPProvider">
      <% String columnName = request.getParameter( "columnName" ); %>
      <% pageContext.setAttribute( "columnName", columnName ); %>
      <% if (columnName.equalsIgnoreCase("right")) { %>
      <TD WIDTH="<dttable:getColumnWidth column="$columnName"/>%" VALIGN=TOP ROWSPAN="<%=tcp.getRowSpan(request)%>"> <% } else { %>
      <TD WIDTH="<dttable:getColumnWidth column="$columnName"/>%" VALIGN=TOP>
      <% } %>
      
    3. Add the following to tabletopbottom.jsp file:


      <jx:if test="$hasChannel">
      <TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>
      <% if (request.getParameter("columnName").equals("bottom")) { %>
      <TR COLSPAN=2>
      <% } else { %>
      <TR>
      <% } %>
      <TD WIDTH="100%" VALIGN=TOP>
      <jx:forEach var="channel" items="$channels">
  8. Copy the PortalServer-DataDir/portals/portal-ID/desktop/classes/JSPTableContainerProvider.properties to PortalServer-DataDir/portals/portal-ID/desktop/classes/SpanTableContainerProvider.properties file.

  9. At least one of the selected channels should be of width full_bottom and the selected layout should be thin_wide_thin for the sample layout to be displayed.

  10. Access SpanTableContainerProvider from your browser. To access, type the following URL in your browser:


    http://hostname:port/portal-ID/dt?provider=SpanTableContainerChannel