public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException
    {
        log.fine("perform: called");

        // Reference the SortForm as a SortForm rather than the generic ActionForm
        SortForm sortForm = (SortForm) form;

        // Get a reference to the session scope
        HttpSession session = request.getSession();

        // Get a reference to the application scope
        ServletContext application = session.getServletContext();

        log.fine("variables in the servlet context: ");

        for (Enumeration e = application.getAttributeNames(); e.hasMoreElements();)
        {
            log.fine(e.nextElement().toString());
        }

        // Get a reference to the list to be sorted
        List list = (List) session.getAttribute(sortForm.getList());

        // Get a reference to the comparator from the application scope to use to perform the sort
        Comparator comparator = (Comparator) application.getAttribute(sortForm.getComparator());

        log.fine("comparator = " + comparator);

        // Get a reference to the current sort state (if there is one)
        SortStateBean sortStateBean = (SortStateBean) session.getAttribute(sortForm.getSortState());

        // Check if there is no sort state bean and create one if so
        if (sortStateBean == null)
        {
            log.fine("There is no sort state bean");

            sortStateBean = new SortStateBean();
        }

        // Determine whether a forward or reverse sort is to be done
        // If its reverse sorted, unsorted or not sorted by the current sort property then forward sort it
        if (!sortStateBean.getState().equals(SortStateBean.FORWARD) ||
                !sortStateBean.getSortProperty().equals(sortForm.getSortStateProperty()))
        {
            // Sort the list
            Collections.sort(list, comparator);

            // Update the current sort state
            sortStateBean.setState(SortStateBean.FORWARD);
        }

        // If its already forward sorted then reverse sort it
        else
        {
            // Sort the list
            Collections.sort(list, comparator);

            // Reverse the list
            Collections.reverse(list);

            // Update the current sort state
            sortStateBean.setState(SortStateBean.REVERSE);
        }

        // Store the sorted list in the variable from which the original list was taken
        session.setAttribute(sortForm.getList(), list);

        // Store the new sort state, setting the property that has been sorted by in the sort state
        sortStateBean.setSortProperty(sortForm.getSortStateProperty());
        session.setAttribute(sortForm.getSortState(), sortStateBean);

        // Forward to the success page
        return (mapping.findForward("success"));
    }
public ActionForward perform ( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) throws IOException , ServletException { log . fine ( "perform: called" ) ; SortForm sortForm = ( SortForm ) form ; HttpSession session = request . getSession ( ) ; ServletContext application = session . getServletContext ( ) ; log . fine ( "variables in the servlet context: " ) ; for ( Enumeration e = application . getAttributeNames ( ) ; e . hasMoreElements ( ) ; ) { log . fine ( e . nextElement ( ) . toString ( ) ) ; } List list = ( List ) session . getAttribute ( sortForm . getList ( ) ) ; Comparator comparator = ( Comparator ) application . getAttribute ( sortForm . getComparator ( ) ) ; log . fine ( "comparator = " + comparator ) ; SortStateBean sortStateBean = ( SortStateBean ) session . getAttribute ( sortForm . getSortState ( ) ) ; if ( sortStateBean == null ) { log . fine ( "There is no sort state bean" ) ; sortStateBean = new SortStateBean ( ) ; } if ( ! sortStateBean . getState ( ) . equals ( SortStateBean . FORWARD ) || ! sortStateBean . getSortProperty ( ) . equals ( sortForm . getSortStateProperty ( ) ) ) { Collections . sort ( list , comparator ) ; sortStateBean . setState ( SortStateBean . FORWARD ) ; } else { Collections . sort ( list , comparator ) ; Collections . reverse ( list ) ; sortStateBean . setState ( SortStateBean . REVERSE ) ; } session . setAttribute ( sortForm . getList ( ) , list ) ; sortStateBean . setSortProperty ( sortForm . getSortStateProperty ( ) ) ; session . setAttribute ( sortForm . getSortState ( ) , sortStateBean ) ; return ( mapping . findForward ( "success" ) ) ; }
Processes the action.

@param     mapping  The ActionMapping used to select this instance
@param     form     The optional ActionForm bean for this request (if any)
@param     request  The HTTP request.
@param     response The HTTP response.

@return    A struts forward to the "success" location.

@exception IOException      if an input/output error occurs
@exception ServletException if a servlet exception occurs