Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.90 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package articlerental;
  7.  
  8. import javax.inject.Named;
  9. import javax.enterprise.context.SessionScoped;
  10. import java.io.Serializable;
  11. import javax.faces.model.DataModel;
  12. import javax.faces.model.ListDataModel;
  13.  
  14. /**
  15.  *
  16.  * @author Antoine
  17.  */
  18. @Named(value = "articleController")
  19. @SessionScoped
  20. public class ArticleController implements Serializable {
  21.  
  22.     int startId;
  23.     int endId;
  24.     DataModel articleList;
  25.     ArticleHelper helper;
  26.     private int recordCount = 1000;
  27.     private int pageSize = 10;
  28.     private String userName = null;
  29.     private String password = null;
  30.    
  31.     private Article current;
  32.     private int selectedItemIndex;
  33.     /**
  34.      * Creates a new instance of ArticleController
  35.      */
  36.     public ArticleController(){
  37.         helper = new ArticleHelper();
  38.         startId = 1;
  39.         endId = 10;
  40.        
  41.     }
  42.    
  43.     public ArticleController(int startId, int endId) {
  44.         helper = new ArticleHelper();
  45.         this.startId = startId;
  46.         this.endId = endId;
  47.     }
  48.    
  49.     public String getUserName() {
  50.         return userName;
  51.     }
  52.  
  53.     public void setUserName(String userName) {
  54.         this.userName = userName;
  55.     }
  56.  
  57.     public String getPassword() {
  58.         return password;
  59.     }
  60.  
  61.     public void setPassword(String password) {
  62.         this.password = password;
  63.     }
  64.    
  65.      public String getauthentification(){
  66.         int result;
  67.        
  68.         result = helper.getLogin(userName, password);      
  69.         System.out.println("Resultat vaut : " + result);
  70.        
  71.         if(result == 0)
  72.             return "index?faces-redirect=true";  //Si l'on ne met que "index", erreur ! la page n'a pas pu être restaurée
  73.        
  74.         if(result == 1)
  75.             return "ListeArticleInventaire";
  76.        
  77.         else
  78.             return "index?faces-redirect=true";
  79.        
  80.     }
  81.      
  82.      public String dbajouterarticle(){
  83.         int result;
  84.        
  85.         return "";
  86.        
  87.     }
  88.      
  89.      public String dbediterarticle(){
  90.         int result;
  91.        
  92.         return "";
  93.        
  94.     }
  95.      
  96.      public Article getSelected(){
  97.          if(current == null){
  98.              current = new Article();
  99.              selectedItemIndex = -1;  
  100.          }
  101.          return current;
  102.      }
  103.      public DataModel getArticleList(){
  104.          if(articleList == null){
  105.              articleList = new ListDataModel(helper.getArticle());
  106.          }
  107.          return articleList;
  108.      }
  109.      
  110.     void recreateModel() {
  111.         articleList = null;
  112.     }
  113.    
  114.     public boolean isHasNextPage() {
  115.         if (endId + pageSize <= recordCount) {
  116.             return true;
  117.         }
  118.         return false;
  119.     }
  120.    
  121.     public boolean isHasPreviousPage() {
  122.         if (startId-pageSize > 0) {
  123.             return true;
  124.         }
  125.         return false;
  126.     }
  127.  
  128.     public String next() {
  129.         startId = endId+1;
  130.         endId = endId + pageSize;
  131.         recreateModel();
  132.         return "index";
  133.     }
  134.  
  135.     public String previous() {
  136.         startId = startId - pageSize;
  137.         endId = endId - pageSize;
  138.         recreateModel();
  139.         return "index";
  140.     }
  141.    
  142.     public int getPageSize() {
  143.         return pageSize;
  144.     }
  145.    
  146.    
  147.     public String editerarticle(){
  148.         current = (Article) getArticleList().getRowData();
  149.         return "Editer";
  150.     }
  151.    
  152.     public String ajouterarticle(){
  153.         recreateModel();
  154.         return "Ajouter";
  155.     }
  156.    
  157.    
  158.     public String supprimerarticle(){
  159.         //helper.supprimer article
  160.         // current = ??
  161.         return "ListeArticleInventaire?faces-redirect=true";
  162.     }
  163.    
  164.     public String retournerindex(){
  165.         recreateModel();
  166.         return "index";
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement