Advertisement
Guest User

ArticleController

a guest
Feb 22nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 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 java.util.ArrayList;
  12. import java.util.List;
  13. import javax.faces.model.DataModel;
  14. import javax.faces.model.ListDataModel;
  15.  
  16. /**
  17. *
  18. * @author Antoine
  19. */
  20. @Named(value = "articleController")
  21. @SessionScoped
  22. public class ArticleController implements Serializable {
  23.  
  24. int startId;
  25. int endId;
  26. Webstockaccess authentification;
  27. DataModel articleList;
  28. ArticleHelper helper;
  29. Article ajouterarticle;
  30. Categorie ajouterarticleCategorie;
  31. Fournisseur ajouterarticleFournisseur;
  32.  
  33. private int recordCount = 1000;
  34. private int pageSize = 10;
  35. private String UserName = null;
  36. private String Password = null;
  37.  
  38. private String ajanom = null; //Ajoiuter Article Nom
  39. private int ajaid; //Ajouter Article Id
  40. private String ajacategorie = null; //Ajouter Article categorie
  41. private String ajafournisseur = null; //Ajouter Article Fournisseur
  42. private String ajadescription = null; //Ajouter Article Description
  43.  
  44. private List articleDescription;
  45. private Article current;
  46. private int selectedItemIndex;
  47. /**
  48. * Creates a new instance of ArticleController
  49. */
  50. public ArticleController() {
  51. helper = new ArticleHelper();
  52. startId = 1;
  53. endId = 10;
  54. }
  55.  
  56. public void setUserName(String UserName) {
  57. this.UserName = UserName;
  58. }
  59.  
  60. public void setPassword(String Password) {
  61. this.Password = Password;
  62. }
  63.  
  64. public String getUserName() {
  65. return UserName;
  66. }
  67.  
  68. public String getPassword() {
  69. return Password;
  70. }
  71.  
  72. public String getauthentification(){
  73. int result;
  74.  
  75. result = helper.getLogin(UserName, Password);
  76. System.out.println("Resultat vaut : " + result);
  77.  
  78. if(result == 0)
  79. return "index?faces-redirect=true"; //Si l'on ne met que "index", erreur ! la page n'a pas pu être restaurée
  80.  
  81. if(result == 1)
  82. return "ListeArticleInventaire";
  83.  
  84. else
  85. return "index?faces-redirect=true";
  86.  
  87. }
  88.  
  89. public DataModel getarticlelist() {
  90. if (articleList == null) {
  91. articleList = new ListDataModel(helper.getArticle());
  92. System.out.print(articleList.getRowCount());
  93. }
  94. return articleList;
  95. }
  96.  
  97. /* public List getarticledescription() {
  98. articleDescription = new ArrayList();
  99. System.out.println("ICIII LA AVANT APPEL FONCTION HELPER ");
  100. //if (articleDescription == null) {
  101. articleDescription = helper.getArticleDescription();
  102.  
  103. //}
  104. return articleDescription;
  105. }
  106. */
  107.  
  108. public String getAjanom() {
  109. return ajanom;
  110. }
  111.  
  112. public void setAjanom(String ajanom) {
  113. this.ajanom = ajanom;
  114. }
  115.  
  116. public int getAjaid() {
  117. return ajaid;
  118. }
  119.  
  120. public void setAjaid(int ajaid) {
  121. this.ajaid = ajaid;
  122. }
  123.  
  124. public String getAjacategorie() {
  125. return ajacategorie;
  126. }
  127.  
  128. public void setAjacategorie(String ajacategorie) {
  129. this.ajacategorie = ajacategorie;
  130. }
  131.  
  132. public String getAjafournisseur() {
  133. return ajafournisseur;
  134. }
  135.  
  136. public void setAjafournisseur(String ajafournisseur) {
  137. this.ajafournisseur = ajafournisseur;
  138. }
  139.  
  140. public String getAjadescription() {
  141. return ajadescription;
  142. }
  143.  
  144. public void setAjadescription(String ajadescription) {
  145. this.ajadescription = ajadescription;
  146. }
  147.  
  148. public void ajouterarticlerequete()
  149. {
  150. ajouterarticle = new Article();
  151. ajouterarticleCategorie = new Categorie();
  152. ajouterarticleFournisseur = new Fournisseur();
  153.  
  154. ajouterarticle.setArticleDescription(ajadescription);
  155. ajouterarticle.setArticleId(ajaid);
  156.  
  157. ajouterarticleCategorie.setArticleCategorie(ajacategorie);
  158. ajouterarticleFournisseur.setFournisseurNom(ajafournisseur);
  159.  
  160. System.out.println("ICI LA CONTROLLER MAGGLE");
  161. //NOm Article ??
  162. //helper.ajouterarticle(this.ajouterarticle, this.ajouterarticleCategorie, this.ajouterarticleFournisseur);
  163. }
  164.  
  165. void recreateModel() {
  166. articleList = null;
  167. }
  168.  
  169. public boolean isHasNextPage() {
  170. if (endId + pageSize <= recordCount) {
  171. return true;
  172. }
  173. return false;
  174. }
  175.  
  176. public boolean isHasPreviousPage() {
  177. if (startId-pageSize > 0) {
  178. return true;
  179. }
  180. return false;
  181. }
  182.  
  183.  
  184. public String next() {
  185. startId = endId+1;
  186. endId = endId + pageSize;
  187. recreateModel();
  188. return "index";
  189. }
  190.  
  191. public String previous() {
  192. startId = startId - pageSize;
  193. endId = endId - pageSize;
  194. recreateModel();
  195. return "index";
  196. }
  197.  
  198. public int getPageSize() {
  199. return pageSize;
  200. }
  201.  
  202. public String prepareView(){
  203. //current = (Article) getFilmTitles().getRowData();
  204. return "browse";
  205. }
  206. public String prepareList(){
  207. recreateModel();
  208. return "index";
  209. }
  210.  
  211. public String editerarticle(){
  212. recreateModel();
  213. return "Editer";
  214. }
  215.  
  216. public String ajouterarticle(){
  217. recreateModel();
  218. return "Ajouter";
  219. }
  220.  
  221. public String supprimerarticle(){
  222. recreateModel();
  223. return "Supprimer";
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement