package controleur;
import Metier.Principale;
import Metier.Livre;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class TriRecherche extends HttpServlet {
public static final String VUE_RECHERCHE = "/Recherche.jsp";
public static final String CHOIX_TRI = "tri";
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.getServletContext().getRequestDispatcher(this.VUE_RECHERCHE).forward( request, response );
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
Principale controleur = Metier.MetierFactory.getPrincipale();
//prendre la derniere recherche
ArrayList<Livre> livres;
livres = (ArrayList<Livre>) session.getAttribute("lastRecherche");
int choix = Integer.parseInt(request.getParameter(this.CHOIX_TRI));
if(choix == 0){
livres = controleur.tri(livres, choix, 1);
} else if(choix == 1) {
livres = controleur.tri(livres, choix, 1);
} else if(choix == 2) {
livres = controleur.tri(livres, choix, 1);
} else {
}
session.setAttribute("lastRecherche", livres);
this.getServletContext().getRequestDispatcher(this.VUE_RECHERCHE).forward( request, response );
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}