Sun Java System Portal Server 7 Developer's Guide

Customizing the Row Layout

This section provides some sample extensions to the JSPTableContainerProvider class file and its associated JSP files for enabling a customized Desktop layout.

ProcedureTo Develop the CustomTCProvider

Steps
  1. Create a new custom table container provider by extending JSPTableContainerProvider.

    Override the getLayout(), setUpColumns(), and getWidths() methods as shown in the CustomTCProvider.java file. You can also add any new logic to arrange the channels into rows and columns according to your new layout.

    CustomTCProvider.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.util.Layout;
    
    import com.sun.portal.providers.context.ContainerProviderContext;
    
    import javax.servlet.http.HttpServletRequest;
    
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    
    public class CustomTCProvider extends JSPTableContainerProvider {
        public int getLayout() throws ProviderException {
            int layout = getIntegerProperty("layout");
            return layout;
        }
    
        public Map setupColumns(HttpServletRequest req) throws ProviderException {
            int layout = getLayout();
            List leftList = new ArrayList();
            List centerList = new ArrayList();
            List rightList = new ArrayList();
            List fullTopList = new ArrayList();
            List fullBottomList = new ArrayList();
            if ((layout >= Layout.LAYOUT_THIN_THICK) && (layout <= Layout.LAYOUT_THIN_THIN_THIN)) {
                return super.setupColumns(req);
            } else {
                List selectedChannels = getSelectedChannels();
                for (Iterator i = selectedChannels.iterator(); i.hasNext(); ) {
                    String providerName = (String)i.next();
                    Provider p = null;
                    p = getContainerProviderContext().getProvider(req,
    getName(), providerName);
                    int width = -1;
                    try {
                        width = p.getWidth();
                    }
                      catch (NumberFormatException e) {
                    }
                      catch (Throwable e) {
                    }
                }
                // add the channel to leftList/centerList/rightList/fullTopList/fullBottomList based on width and as required by your new layout.
            }
            Map<Integer,List> columnMap = new HashMap<Integer,List>();
    
            columnMap.put( new Integer(LEFT), leftList );
            columnMap.put( new Integer(RIGHT), rightList );
            columnMap.put( new Integer(CENTER), centerList );
            columnMap.put( new Integer(TOP), fullTopList );
            columnMap.put( new Integer(BOTTOM), fullBottomList );
            return columnMap;
        }
        public int getWidths(int column) throws ProviderException {
            int centerWidth = -1;
            int leftWidth = -1;
            int rightWidth = -1;
            /* modify this method as shown in the customizing column widths
    section according to your layout specifications or keep this method as is.*/
            //return the corresponding width based on the column.
            switch( column ) {
                case LEFT:
                return leftWidth;
                case RIGHT:
                return rightWidth;
                case CENTER:
                return centerWidth;
                default:
                return -1;
            }
        }
    }
  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 CustomTCProvider.java file, enter:


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

    1. The display profile fragment for the CustomTCProvider’s provider and channel must be saved in separate XML files.

    2. Add <Integer name="layout" value="5"/> in the display profile fragment for the CustomTCProvider’s provider.

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

  4. Create a new directory for the provider in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory and copy files from PortalServer-DataDir/portals/portal-ID/desktop/default/JSPTableContainerProvider to the newly created directory.

    The directory for the provider is typically named after the provider. For the sample CustomTCProvider, create a directory called CustomTCProvider in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory.

  5. Modify the HTML in toptable.jsp file in PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/CustomTCProvider.

    Rearrange the channels into rows and columns as per your specifications. Replace JSPLayoutContainer with CustomLayoutContainer.

  6. Create a new directory for CustomLayoutContainer under PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory and copy files from PortalServer-DataDir/portals/portal-ID/desktop/default/JSPLayoutContainer to PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/CustomLayoutContainer directory.

    For example, type:


    mkdir PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/CustomLayoutContainer
    cp PortalServer-DataDir/portals/portal-ID/desktop/default/JSPLayoutContainer/* PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/CustomLayoutContainer
  7. Modify layoutedit.jsp to display your new layout in the layout page.

    Modify the layoutedit.jsp file at PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/CustomLayoutContainer.

    layoutedit.jsp File


    <jx:choose>
        <jx:when test="$layout == 1">
            <%@ include file="layout1.jsp" %>
        </jx:when>
        <jx:when test="$layout == 2">
            <%@ include file="layout2.jsp" %>
        </jx:when>
        <jx:when test="$layout == 3">
            <%@ include file="layout3.jsp" %>
        </jx:when>
        <jx:when test="$layout == 5">
            <%@ include file="layout5.jsp" %>
        </jx:when>
    </jx:choose>
  8. Create a new layout5.jsp which gets displayed on the layout page when the user selects layout 5 and modify layoutdoedit.jsp to handle the processing of layout 5 that you have created.

  9. Add the display profile for CustomLayoutContainer as shown in CustomLayoutContainer.xml file and upload the display profile XML fragment for CustomLayoutContainer using the psadmin command.

    CustomLayoutContainer.xml File


    <Container name="CustomLayoutContainer" provider="JSPSingleContainerProvider" advanced="true">
        <Properties>
            <String name="title" value="JSP Custom Layout Channel"/>
            <String name="description" value="This is the JSP Layout Channel"/>
            <String name="contentPage" value="" merge="replace" lock="false" propagate="false"/>
            <String name="editPage" value="layoutedit.jsp"/>
            <String name="processPage" value="layoutdoedit.jsp"/>
            <Boolean name="isEditable" value="true" advanced="true"/>
            <String name="editType" value="edit_complete" advanced="true"/>
        </Properties>
    
        <Available>
        </Available>
        <Selected>
        </Selected>
        <Channels>
        </Channels>
    </Container>

    To upload CustomLayoutContainer.xml file fragments, use the psadmin add-display-profile subcommand. See the Sun Java System Portal Server 7 Command-Line Reference for more information on this subcommand.

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


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