4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
Menu.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: Menu.java
5  * Description: Backbean for template.xhtml, class for menu handling
6  */
7 
8 /**
9  * @file Menu.java
10  *
11  * @brief Backbean for template.xhtml, class for menu handling
12  */
13 
14 package cz.vutbr.fit.knot.annotations.web;
15 
16 import java.io.Serializable;
17 import javax.faces.bean.ManagedBean;
18 import javax.faces.bean.SessionScoped;
19 
20 /**
21  * Backbean for template.xhtml, class for menu handling
22  *
23  * @brief Backbean for template.xhtml, class for menu handling
24  * @author idytrych
25  */
26 @ManagedBean
27 @SessionScoped
28 public class Menu implements Serializable {
29  /**
30  * Page actually displayed
31  */
32  private String actualPage = "index";
33 
34  /**
35  * Action listener for all menu buttons (except log off)
36  * - ensure the transition
37  * - clears errors on login page
38  *
39  * @param newPage New page to display (identification of button)
40  * @return Returns page outcome (identification of transition)
41  */
42  public String menuAction(String newPage) {
43  if (!actualPage.equals("login") && newPage.equals("login")) {
44  Login loginBean = (Login) SessionManager.getBeanByName("login");
45  loginBean.setBadCredentials(false);
46  }
47  actualPage = newPage;
48  return newPage;
49  }
50 
51  /**
52  * Action listener for log off menu button
53  * - log off the user
54  * - switch to index page
55  *
56  * @return Returns page outcome to go to index page
57  */
58  public String logoffAction() {
59  SessionManager.getSession().setNotLoggedIn();
60  Login loginBean = (Login) SessionManager.getBeanByName("login");
61  if (loginBean != null) { // clean up login form
62  loginBean.setLogin("");
63  loginBean.setPassword("");
64  loginBean.setBadCredentials(false);
65  }
66  actualPage = "index";
67  return "index";
68  }
69 
70  /**
71  * Returns whether menu item is disabled (page is now displayed)
72  *
73  * @param page Identificator of menu item
74  * @return If page is now displayed, returns true, false otherwise
75  */
76  public String isDisabled(String page) {
77  if (page == null ? actualPage == null : page.equals(actualPage)) {
78  return "true";
79  } else {
80  return "false";
81  }
82  }
83 
84  /**
85  * Gets whether user is logged in
86  *
87  * @return If user is logged in, returns true, false otherwise
88  */
89  public boolean getLoggedIn() {
90  return SessionManager.getSession().isLoggedIn();
91  }
92 
93  /**
94  * Returns whether user is an administrator
95  *
96  * @return If user is administrator, returns true, false otherwise
97  */
98  public boolean getIsAdmin() {
99  return SessionManager.getSession().isAdmin();
100  }
101 
102  /**
103  * Gets identification of now displayed page
104  *
105  * @return Returns identification of page now displayed
106  */
107  public String getActualPage() {
108  return actualPage;
109  }
110 
111  /**
112  * Sets page now displayed (for transitions out of menu)
113  *
114  * @param actualPage Identificator of actually displayed page
115  */
116  public void setActualPage(String actualPage) {
117  this.actualPage = actualPage;
118  }
119 
120  /**
121  * Constructor
122  */
123  public Menu() {
124  }
125 
126 } // public class Menu
Class for manipulating with session.
Backbean for template.xhtml, class for menu handling.
Definition: Menu.java:28
String menuAction(String newPage)
Definition: Menu.java:42
Backbean for login page.
Definition: Login.java:38
String isDisabled(String page)
Definition: Menu.java:76
void setActualPage(String actualPage)
Definition: Menu.java:116