The default sort for the RcWebBrowse.jsp page is by TITLE only, how can I change that?

The line of jsp code that controls the sort is listed below.

Collections.sort(l, ArmadilloSearcher.ARMADILLO_DOCUMENT_COMPARATOR);

The standard TITLE search is written into ArmadilloSearcher.ARMADILLO_DOCUMENT_COMPARATOR

To change the sort we need to create a new Comparator and include the java.util.Compator in our imports.

Add the following bolded line to your imports area by opening your RcWebBrowse.jsp file in an editor.  Looking at the start of the file you should find the following lines,  Add the bold line below (remember to add the , at the end of the line).

 

<jsp:directive.page language=\"java\"
contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"
import=\"
java.util.Arrays,
java.util.Collections,


java.util.Comparator,

java.util.Enumeration,
java.util.Hashtable,
java.util.Iterator, ...

 

then replace the default Comparator with a new one.  Find the following line of code in the RcWebBrowse.jsp file and comment it out or delete it.

Collections.sort(l, ArmadilloSearcher.ARMADILLO_DOCUMENT_COMPARATOR);

 

At the same spot in the file add the following lines of code...

Comparator c = new Comparator()

{

public int compare( Object o1, Object o2 )

{
final String comp1 = ((ArmadilloDocument)o1).getTitle().trim().toLowerCase()+((ArmadilloDocument)o1).getPubDate().trim().toLowerCase()+((ArmadilloDocument)o1).getVolume().trim().toLowerCase();
final String comp2 = ((ArmadilloDocument)o2).getTitle().trim().toLowerCase()+((ArmadilloDocument)o2).getPubDate().trim().toLowerCase()+((ArmadilloDocument)o2).getVolume().trim().toLowerCase();
return comp1.compareTo( comp2 );
}
};

Collections.sort(l, c);

To reflect the same sort in the RcWebImageViewer.jsp page

add the java.util.Comparator, as above

<jsp:directive.page language=\"java\"
contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"
import=\"
java.util.Arrays,
java.util.Collections,

java.util.Comparator,

java.util.Enumeration,
java.util.Hashtable,
java.util.Iterator, ..

 

Then find and replace the line

Collections.sort(rcAr2DocLst, ArmadilloSearcher.ARMADILLO_DOCUMENT_COMPARATOR);


with

//Collections.sort(rcAr2DocLst, ArmadilloSearcher.ARMADILLO_DOCUMENT_COMPARATOR);
//Default title sort
Comparator c = new Comparator()
{
public int compare( Object o1, Object o2 )
{
final String comp1 = ((ArmadilloDocument)o1).getTitle().trim().toLowerCase()+((ArmadilloDocument)o1).getPubDate().trim().toLowerCase()+((ArmadilloDocument)o1).getVolume().trim().toLowerCase();
final String comp2 = ((ArmadilloDocument)o2).getTitle().trim().toLowerCase()+((ArmadilloDocument)o2).getPubDate().trim().toLowerCase()+((ArmadilloDocument)o2).getVolume().trim().toLowerCase();
return comp1.compareTo( comp2 );
}
};
Collections.sort(rcAr2DocLst, c);
// End of new comparator sort on Pubdate and Volume

The code lines above takes the TITLE and adds the PublicationDate and Volume to the sort. This is useful for serial publications where the TITLE is the same but the items may have been added to the collection out of order.

 

We will incorporate this into the next version of ResCarta-Web as an option in the WEB-INF/web.xml file. Until then enjoy!!!