JSP is just a presentation technology and should in fact not contain any business logic/algorithms.
That said, I don't know Trinidad, but have you checked if it doesn't provide a sortable table (or column) component? That would be much more easier. Just let Trinidad do all the sorting work. Consult the documentation along it for details. It is also available at their homepage as well.