Sorting channels on Personalize Page

Hello,

I am trying to sort channels on a Personalize page alphabetically. This is the contentedit.jsp in JSPContentContainer. Later functionality is I'd like to be able to sort by another field. The channels are aquired and placed in a java.util.List called missedChannels. I tried the method Collections.sort(missedChannels); and it is working to a certain extent to sort alphabetically, but then it is getting the channels out of order again as if things are getting out of order later in the jsp. All my channels are uncategorized so I thought that my list would not be manipulated in the code preceding the listing of the uncategorized channels, keeping them in order.

The JSP code for 1st half of jsp is as follows:

<%--

Copyright 2003 Sun Microsystems, Inc. All rights reserved

Use is subject to license terms.

--%>

<%-- contentedit.jsp --%>

<%@ page import="com.sun.portal.providers.containers.jsp.single.JSPSingleContainerProvid er,

com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider,

com.sun.portal.providers.Provider,

com.sun.portal.providers.ProviderWidths,

com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab,

java.util.Map,

java.util.Iterator,

java.util.Collections,

java.util.List,

java.util.ArrayList,

java.lang.Boolean"

%>

<%@ page session="false" %>

<%@ taglib uri="/tld/desktop.tld" prefix="dt" %>

<%@ taglib uri="/tld/jx.tld" prefix="jx" %>

<%@ taglib uri="/tld/desktopProviderContext.tld" prefix="dtpc" %>

<%@ taglib uri="/tld/desktopContainerProviderContext.tld" prefix="dtcpc" %>

<%@ taglib uri="/tld/desktopTheme.tld" prefix="dttheme" %>

<%

JSPSingleContainerProvider scp = (JSPSingleContainerProvider)pageContext.getAttribute("JSPProvider");

String container = (String)request.getParameter("container");

pageContext.setAttribute( "container", container, PageContext.REQUEST_SCOPE );

String parentContainer = scp.getProviderContext().getDefaultChannelName();

String parentContainerProvider = scp.getProviderContext().getProviderName(parentContainer);

String selectedTabName = request.getParameter("selected");

JSPTableContainerProvider tcp = (JSPTableContainerProvider)scp.getContainerProviderContext().getProvider(reques t, scp.getName(), container);

pageContext.setAttribute( "tableProvider", tcp );

String fontFace1 = (String)pageContext.getAttribute("fontFace1", PageContext.REQUEST_SCOPE);

%>

<dt:obtainContainer container="$tableProvider">

<dtcpc:containerProviderContext>

<dt:getAvailableChannels id="availableChannels"/>

<dt:getSelectedChannels id="selectedChannels"/>

<jx:declare id="selectedChannels" type="List"/>

<jx:declare id="availableChannels" type="List"/>

<jsp:include page="personalizeHeader.jsp" flush="true"/>

<script language="JavaScript" type="text/javascript">

<%@ include file="close-windows.jsp" %>

var popup_window;

function launchPopup(url, name, width, height) {

popup_window = window.open( url, name, 'width=' + width + ',height=' + height +',resizable=yes,scrollbars=yes');

}

</script>

<%@ include file="contentLayoutBar.jsp" %>

<FORM ACTION="<dtpc:getDesktopURL/>" TARGET="_parent" METHOD="POST" NAME="contentForm" ENCTYPE="application/x-www-form-urlencoded" >

<INPUT TYPE=HIDDEN NAME="action" SIZE=-1 VALUE="process">

<INPUT TYPE=HIDDEN NAME="provider" SIZE=-1 VALUE="JSPContentContainer">

<INPUT TYPE=HIDDEN NAME="container" SIZE=-1 VALUE="<%=container%>">

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">

<TR>

<TD ALIGN="CENTER">

<CENTER>

<P>

<TABLE BORDER="0" CELLPADDING=2 CELLSPACING="0" WIDTH="100%">

<TR>

<TD COLSPAN="2">

<FONT COLOR="<dttheme:getAttribute name="tabFontColor" default="#000000"/>" SIZE="+0" FACE="<dttheme:getAttribute name="contentLayoutText" default="Verdana"/>"><b>

Select the Channels you would like displayed on this Page.
</b>

</FONT>

</TD>

</TR>

<TR><TD COLSPAN="2">

<B><FONT SIZE="-1">Legend: T = thin column, W = wide column, FT = full top column, FB = full bottom column</FONT></B>

</TD>

</TR>

<TR><td bgcolor="#FFFFFF"><img src="<dt:scontent/>/images/spacer.gif" width=

"100%" height="20" alt="Spacer Image"></td></TR>

<tr>

<td>

<TABLE BORDER="0" CELLPADDING=2 CELLSPACING="0" WIDTH="420" >

<tr bgcolor="#CCCCCC" valign="top">

<td height="3" colspan="3">

<div align="left">

<b><font size="-1" color="white" face="Arial, Helvetica, sans-serif">

<a name="AZChannel">A-to-Z Channel List</a>

</font>

</b>

</div>

</td>

</TR>

</TABLE>

</td>

</tr>

<tr valign="top">

<td>

<TABLE BORDER="0" CELLPADDING=2 CELLSPACING="0" WIDTH="420" >

<tr>

<td>

<div align="left">

<font face="Arial, Helvetica, sans-serif" size="2">

<a href="#A">A</a>

<a href="#B" >B</a> <a href="#C" >C</a> <a href="#D" >D</a> <a href="#E" >E</a>

<a href="#F" >F</a> <a href="#G" >G</a> <a href="#H" >H</a> <a href="#I" >I</a>

<a href="#J" >J</a> <a href="#K" >K</a> <a href="#L" >L</a> <a href="#M" >M</a>

<a href="#N" >N</a> <a href="#O" >O</a> <a href="#P" >P</a> <a href="#Q" >Q</a>

<a href="#R" >R</a> <a href="#S" >S</a> <a href="#T" >T</a> <a href="#U" >U</a>

<a href="#V" >V</a> <a href="#W" >W</a> <a href="#X" >X</a> <a href="#Y" >Y</a>

<a href="#Z" >Z</a>

<a href="#0" >0-9</a>

</font>

</div>

</td>

</tr>

</TABLE>

</td>


</tr>

<tr>

<td>

<TABLE BORDER="0" CELLPADDING=2 CELLSPACING="0" WIDTH="420" >

<tr>

<td width="330" colspan="2">

<img src="/desktop/mqportal/external/images/name.jpg" alt="Sort by Name">

</td>

<td width="30">

<img src="/desktop/mqportal/external/images/more_info.jpg" alt="More Info">

</td>

<td width="60">

<img src="/desktop/mqportal/external/images/request_access.jpg" alt="Request for Activation">

</td>

</tr>

<%-- Get the list of categories for this container --%>

<dtpc:getLocalePropertiesFilters id="localeFilter"/>

<dtpc:getCollectionProperty key="categories" pfList="$localeFilter" id="categories"/>

<%-- Declare categories, because it will be used in scriptlets --%>

<jx:declare id="categories" type="Map"/>

<jx:declare id="categEntry" type="String"/>

<%-- Create the arraylist --%>

<%

int channelTotal= 0; // Total number of channels in the page

int channelCount= 0; // Channels in a caegory

List leftList= null;// Left column categories

int leftChannelCount= 0; // Total number of channels in the left column

int categCount = categories.size(); // Category Count

List rightList = new java.util.ArrayList(); // Right column categories

List categsWithCount= new java.util.ArrayList(categCount); // List with n:category format - n # of channels

StringBuffer buf= new StringBuffer();

String currentChar= "0"; // Used to decide whether to display the alphabet header

//Get the iterator to get all the channels for each category

Iterator itr = categories.keySet().iterator();

String tempVar = null;

String leftColumn = "notEmpty";

String rightColumn = "notEmpty";

ListstrayList= null;

// Get a copy of the available channels and remove the channels with category information

// from the list, which will be the list of channels with no categories.

// Shallow copy will do the job here, hence clone.

List missedList = new ArrayList(availableChannels);

Collections.sort(missedList); //Added following line to sort list alphabetically

String [] missedChannels = null;

// Build up a list with entry of the format n:categoryName where

// n is the number of channels for the category. This is required to

// build up a plan to effectively use the real estate on the page.

// The mapping between the categories and the channel count has to be

// preserved but we need a sorted list, so build a string list like this.

while(itr.hasNext()) {

// Get one category at a time

categEntry = (String)itr.next();

// Set the category in the pagecontext to be used by the tags

pageContext.setAttribute("categEntry",categEntry);

%>

[10905 byte] By [Erly-Dev] at [2007-11-25 19:42:08]
# 1

Sorry about the code post.I shouldn't have done that but too late. I solved my sort problem. I was just displaying the wrong variable, the title of the channel but it was being sorted by channel name with the Collections.sort(missedList); command, so the channels were not actually out of order at all, the titles don't always match with the channel name.

It would still be nice if I could find out how to sort the list using various criteria of string values in different fields. If someone can help with that it would be appreciated!

ErlyDev at 2007-7-4 12:48:34 > top of Java-index,Web & Directory Servers,Portal Servers...
# 2
which portal version are you using ?/u
UlfFeger at 2007-7-4 12:48:34 > top of Java-index,Web & Directory Servers,Portal Servers...
# 3
I am using version 6.2
ErlyDev at 2007-7-4 12:48:34 > top of Java-index,Web & Directory Servers,Portal Servers...