Package actions

Source Code of actions.MonProfilAction


package actions;

import interfaces.clients.IMetierClients;
import interfaces.exceptions.MetierException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//import metier.clients.MetierClients;
import ressources.Message;
import base.Client;

public class MonProfilAction implements Action {
 


    private String suite,erreur,noErreur;
   
    public MonProfilAction(String suite,String noErreur,String erreur){
      this.suite = suite;
      this.erreur = erreur;
      this.noErreur = noErreur;
    }
   
    /**
     *
     */
    public String execute(HttpServletRequest req) throws Exception {
      String actionModif = req.getParameter(Message.ACTION_MODIF_ADRESSE);
     
      IMetierClients mc = (IMetierClients)req.getSession().getServletContext().getAttribute("metierClients");
      //MetierClients mc = new MetierClients();
     
     
     
      if(actionModif != null){           
         
          String adresse = req.getParameter("adresse");
          if(!verifierChaine(adresse)){
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_ADRESSE);         
            return erreur;
          }       
                             
         
          try{         
            HttpSession session = req.getSession(false);
            if(session != null){
              Client client = (Client)session.getAttribute("client");
              if(client == null){
                throw new MetierException();
              }
              System.out.println("Adresse : "+adresse);
              // On modifie l'adresse du client
              client.setAdresse(adresse);
              mc.modifierAdresse(client);
             
              // On remet l'adresse dans la session
              session.setAttribute("client", client);
             
              // Tout est ok
              return noErreur;
            }
           
          }catch(MetierException me){
            me.printStackTrace();
            req.setAttribute(Message.MESSAGE_ERREUR, Message.MODIF_ADRESSE_IMPOSSIBLE);
            return erreur;
          }
         
       
      }
     
     
      return suite;
    }
   
   
    /**
     * Si aucun problème, on renvoit true
     *
     * @param chaine La chaine à vérifier
     * @return
     */
    private boolean verifierChaine(String chaine){
      if(chaine == null || chaine.trim().equals("")){
        return false;
      }
     
      return true;
    }

}
TOP

Related Classes of actions.MonProfilAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.