comparatorChain.addComparator(new BeanComparator("state.degreeState"));
comparatorChain.addComparator(new BeanComparator("state"));
    public ActionForward choose(ActionMapping mapping, ActionForm form, HttpServletRequest request,            HttpServletResponse response) throws Exception {        HttpSession session = request.getSession(false);        DynaActionForm chooseExamContextoForm = (DynaActionForm) form;        SessionUtils.removeAttributtes(session, SessionConstants.CONTEXT_PREFIX);        if (session != null) {            ActionErrors errors = new ActionErrors();            InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) request                    .getAttribute(SessionConstants.EXECUTION_PERIOD);            String[] selectedCurricularYears = (String[]) chooseExamContextoForm                    .get("selectedCurricularYears");            Boolean selectAllCurricularYears = (Boolean) chooseExamContextoForm                    .get("selectAllCurricularYears");            Integer degreeId = (Integer) chooseExamContextoForm.get("degreeID");            if ((selectAllCurricularYears != null) && selectAllCurricularYears.booleanValue()) {                String[] allCurricularYears = { "1", "2", "3", "4", "5" };                selectedCurricularYears = allCurricularYears;            }            List curricularYears = new ArrayList(selectedCurricularYears.length);            for (int i = 0; i < selectedCurricularYears.length; i++)                curricularYears.add(new Integer(selectedCurricularYears[i]));            request.setAttribute("curricularYearList", curricularYears);            Integer indexValue = getFromRequest("index", request);            //	int index = indexValue.intValue();            request.setAttribute("index", indexValue);            Integer degreeCurricularPlanId = getFromRequest("degreeCurricularPlanID", request);            request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanId);            // Integer degreeId = getFromRequest("degreeID", request);            request.setAttribute("degreeID", degreeId);			Integer indice = (Integer)chooseExamContextoForm.get("indice");            String language = getLocaleLanguageFromRequest(request);            			List executionPeriodsLabelValueList = new ArrayList();		    executionPeriodsLabelValueList = getList(degreeCurricularPlanId);		    if (executionPeriodsLabelValueList.size() > 1) {							   request.setAttribute("lista",executionPeriodsLabelValueList);            } else {				   request.removeAttribute("lista");		    }			request.setAttribute("indice",indice);			Object argsLerLicenciaturas[] =null;			if (indice != null) {			InfoExecutionPeriod infoExecutionPeriod2 = new InfoExecutionPeriod();			Object args[] = {indice};			try {				infoExecutionPeriod2 = (InfoExecutionPeriod )ServiceManagerServiceFactory.executeService(null,				"ReadExecutionPeriodByOID", args);			}catch(FenixServiceException e){				errors.add("impossibleDegreeSite", new ActionError("error.impossibleDegreeSite"));				saveErrors(request, errors);				return (new ActionForward(mapping.getInput()));			}			 infoExecutionPeriod = infoExecutionPeriod2;			 RequestUtils.setExecutionPeriodToRequest(request,infoExecutionPeriod2);             argsLerLicenciaturas= new Object[]{infoExecutionPeriod2.getInfoExecutionYear().getIdInternal()};			}else {				argsLerLicenciaturas= new Object[]{infoExecutionPeriod.getInfoExecutionYear().getIdInternal()};			}            List infoExecutionDegreeList = (List) ServiceUtils.executeService(null,                    "ReadExecutionDegreesByExecutionYearId", argsLerLicenciaturas);            Collections.sort(infoExecutionDegreeList, new ComparatorByNameForInfoExecutionDegree());            InfoExecutionDegree infoExecutionDegree1 = new InfoExecutionDegree();            Iterator iterator = infoExecutionDegreeList.iterator();            while (iterator.hasNext()) {                infoExecutionDegree1 = (InfoExecutionDegree) iterator.next();                if (infoExecutionDegree1.getInfoDegreeCurricularPlan().getIdInternal().equals(                        degreeCurricularPlanId)) {                    //		request.setAttribute("infoDegreeCurricularPlan",                    // infoExecutionDegree1);                    break;                }            }            /*             * InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree)             * infoExecutionDegreeList.get(index);             */            InfoExecutionDegree infoExecutionDegree = infoExecutionDegree1;            //**************************************/            Object[] args1 = {degreeId};            List infoDegreeCurricularPlanList = null;            try {                infoDegreeCurricularPlanList = (List) ServiceManagerServiceFactory.executeService(null,                        "ReadPublicDegreeCurricularPlansByDegree", args1);            } catch (FenixServiceException e) {                errors.add("impossibleDegreeSite", new ActionError("error.impossibleDegreeSite"));                saveErrors(request, errors);                return (new ActionForward(mapping.getInput()));            }            //order the list by state and next by begin date            ComparatorChain comparatorChain = new ComparatorChain();            comparatorChain.addComparator(new BeanComparator("state.degreeState"));            comparatorChain.addComparator(new BeanComparator("initialDate"), true);            Collections.sort(infoDegreeCurricularPlanList, comparatorChain);            if (degreeCurricularPlanId != null) {                Iterator iterator1 = infoDegreeCurricularPlanList.iterator();                while (iterator1.hasNext()) {                    InfoDegreeCurricularPlan infoDegreeCurricularPlanElem = (InfoDegreeCurricularPlan) iterator1                            .next();                    if (infoDegreeCurricularPlanElem.getIdInternal().equals(degreeCurricularPlanId)) {                        infoDegreeCurricularPlanElem.prepareEnglishPresentation(language);                        request.setAttribute("infoDegreeCurricularPlan", infoDegreeCurricularPlanElem);                        break;                    }                }            }            //***************************************/            request.setAttribute(SessionConstants.EXECUTION_PERIOD, infoExecutionPeriod);            request.setAttribute(SessionConstants.EXECUTION_PERIOD_OID, infoExecutionPeriod                    .getIdInternal().toString());            if (infoExecutionDegree != null) {                //added by rspl                request.setAttribute(SessionConstants.EXECUTION_DEGREE, infoExecutionDegree);                //-----------------                request                        .setAttribute("executionDegreeID", infoExecutionDegree.getIdInternal()                                .toString());                RequestUtils.setExecutionDegreeToRequest(request, infoExecutionDegree);                /*                 * request.setAttribute( "infoDegreeCurricularPlan",                 * (InfoDegreeCurricularPlan)infoExecutionDegree.getInfoDegreeCurricularPlan());                 */            } else {                return mapping.findForward("Licenciatura execucao inexistente");            }        } else            throw new Exception();        // nao ocorre... pedido passa pelo filtro Autorizacao        return mapping.findForward("showExamsMap");    }