Example #1
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // recupération de la personne en base
    Integer profileId = Integer.valueOf(request.getParameter("profileId"));
    // recherche de la personne à modifier
    Personne updatedPerson = new Personne();
    updatedPerson.setId(profileId);
    updatedPerson = gestionEcoleService.rechercherPersonne(updatedPerson).get(0);
    // affectation des nouvelles valeurs
    String inputNom = request.getParameter("inputNom");
    updatedPerson.setNom(inputNom);
    String inputPrenom = request.getParameter("inputPrenom");
    updatedPerson.setPrenom(inputPrenom);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
    String inputDateNaissString = request.getParameter("inputDateNaiss");
    try {
      Date inputDateNaiss = simpleDateFormat.parse(inputDateNaissString);
      updatedPerson.setDateNaiss(inputDateNaiss);
    } catch (ParseException e) {
      throw new RuntimeException(e);
    }

    String inputPassword = request.getParameter("inputPassword");
    if (inputPassword != null && !inputPassword.isEmpty()) {
      updatedPerson.setPassw(inputPassword);
    }

    String inputPromotionString = request.getParameter("inputPromotion");
    if (!inputPromotionString.isEmpty()) {
      Integer inputPromotion = Integer.valueOf(inputPromotionString);
      Promotion searchPromotion = new Promotion();
      searchPromotion.setId(inputPromotion);
      searchPromotion = gestionEcoleService.rechercherPromotion(searchPromotion).get(0);
      updatedPerson.setPromotion(searchPromotion);
    } else {
      updatedPerson.setPromotion(null);
    }

    // mise à jour
    updatedPerson = gestionEcoleService.updatePersonne(updatedPerson);

    request.setAttribute("personneSelected", updatedPerson);
    RequestDispatcher dispatcher = request.getRequestDispatcher("/TP5_Controller");
    dispatcher.forward(request, response);
  }
Example #2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter printWriter = response.getWriter();

    Integer ligne = null;
    String ligneParam = request.getParameter("ligne");
    if (ligneParam != null) {
      ligne = Integer.valueOf(ligneParam);
    }

    if (ligne != null) {
      System.out.println("numero de ligne cliquée : ".concat(String.valueOf(ligne)));
    }

    List<Personne> personnes = new ArrayList<Personne>();

    Promotion promotion = new Promotion();
    promotion.setLibelle("CDI09");

    Personne personne1 = new Personne();
    personne1.setNom("toto");
    personne1.setPrenom("toto");
    personne1.setDateNaiss(new Date());
    personne1.setPromotion(promotion);
    personnes.add(personne1);

    Personne personne2 = new Personne();
    personne2.setNom("tata");
    personne2.setPrenom("tata");
    personne2.setDateNaiss(new Date());
    personne2.setPromotion(promotion);
    personnes.add(personne2);

    printWriter.println("<!DOCTYPE html>");
    printWriter.println("<html>");
    printWriter.println("<head>");
    printWriter.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
    printWriter.println("</head>");
    printWriter.println("<body>");
    printWriter.println(
        "<table><thead><tr><th>nom</th><th>prenom</th><th>date naissance</th><th>promotion</th></tr></thead><tbody>");
    Integer cpt = 1;
    for (Personne personne : personnes) {
      printWriter.println(
          "<tr><td>"
              .concat(personne.getNom())
              .concat("</td><td>")
              .concat(personne.getPrenom())
              .concat("</td><td>")
              .concat(personne.getDateNaiss().toString())
              .concat("</td><td>")
              .concat(personne.getPromotion() != null ? personne.getPromotion().getLibelle() : "")
              .concat("</td><td>")
              .concat(
                  "<a href=\"./TP7?ligne="
                      .concat(String.valueOf(cpt++))
                      .concat("\">afficher ligne dans console</a>"))
              .concat("</td></tr>"));
    }
    printWriter.println("</tbody></table>");

    printWriter.println("</body>");
    printWriter.println("</html>");
  }