Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package articlerental;
- import javax.inject.Named;
- import javax.enterprise.context.SessionScoped;
- import java.io.Serializable;
- import javax.faces.model.DataModel;
- import javax.faces.model.ListDataModel;
- /**
- *
- * @author Antoine
- */
- @Named(value = "articleController")
- @SessionScoped
- public class ArticleController implements Serializable {
- int startId;
- int endId;
- DataModel articleList;
- ArticleHelper helper;
- private int recordCount = 1000;
- private int pageSize = 10;
- private String userName = null;
- private String password = null;
- private Article current;
- private int selectedItemIndex;
- /**
- * Creates a new instance of ArticleController
- */
- public ArticleController(){
- helper = new ArticleHelper();
- startId = 1;
- endId = 10;
- }
- public ArticleController(int startId, int endId) {
- helper = new ArticleHelper();
- this.startId = startId;
- this.endId = endId;
- }
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getauthentification(){
- int result;
- result = helper.getLogin(userName, password);
- System.out.println("Resultat vaut : " + result);
- if(result == 0)
- return "index?faces-redirect=true"; //Si l'on ne met que "index", erreur ! la page n'a pas pu être restaurée
- if(result == 1)
- return "ListeArticleInventaire";
- else
- return "index?faces-redirect=true";
- }
- public String dbajouterarticle(){
- int result;
- return "";
- }
- public String dbediterarticle(){
- int result;
- return "";
- }
- public Article getSelected(){
- if(current == null){
- current = new Article();
- selectedItemIndex = -1;
- }
- return current;
- }
- public DataModel getArticleList(){
- if(articleList == null){
- articleList = new ListDataModel(helper.getArticle());
- }
- return articleList;
- }
- void recreateModel() {
- articleList = null;
- }
- public boolean isHasNextPage() {
- if (endId + pageSize <= recordCount) {
- return true;
- }
- return false;
- }
- public boolean isHasPreviousPage() {
- if (startId-pageSize > 0) {
- return true;
- }
- return false;
- }
- public String next() {
- startId = endId+1;
- endId = endId + pageSize;
- recreateModel();
- return "index";
- }
- public String previous() {
- startId = startId - pageSize;
- endId = endId - pageSize;
- recreateModel();
- return "index";
- }
- public int getPageSize() {
- return pageSize;
- }
- public String editerarticle(){
- current = (Article) getArticleList().getRowData();
- return "Editer";
- }
- public String ajouterarticle(){
- recreateModel();
- return "Ajouter";
- }
- public String supprimerarticle(){
- //helper.supprimer article
- // current = ??
- return "ListeArticleInventaire?faces-redirect=true";
- }
- public String retournerindex(){
- recreateModel();
- return "index";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement