Erreur java.lang.NumberFormatException: For input string: "null" sur clique menuitem
Bonjour,
Dans mon appli JSF/PF, j'ai un menu que je construis avec un DefaultMenuModel.
J'ai notamment le MenuItem "Déconnexion :
Code:
1 2 3 4 5 6 7 8 9
|
/**
* Construis le sous-menu "Déconnexion"
*/
private void buildMenuDeconnexion() {
DefaultMenuItem deconnexion = new DefaultMenuItem(getMessage("Deconnexion"), "ui-icon-close");
deconnexion.setCommand("#{menuView.logout}");
menuModel.addElement(deconnexion);
} |
Qui appelle la méthode logout() :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
/**
* Méthode de déconnexion de l'utilisateur
*/
public void logout() {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext externalContext = context.getExternalContext();
try {
HttpSession session = ((HttpServletRequest) externalContext
.getRequest()).getSession();
session.invalidate();
externalContext.redirect(externalContext.getRequestContextPath() + IUrlLocation.URL_LOGIN);
} catch (Exception e) {
context.addMessage(null, new FacesMessage(e.getMessage()));
}
} |
L'URL login :
Code:
public static final String URL_LOGIN = "/connexion/login.xhtml";
Le filtre, référencé par l'erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
public class LoginFilter implements Filter {
/**
* Checks if user is logged in. If not it redirects to the login.xhtml page.
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Get the loginBean from session attribute
Utilisateur loginBean = (Utilisateur) ((HttpServletRequest) request).getSession().getAttribute("user");
// For the first application request there is no loginBean in the session so user needs to log in
// For other requests loginBean is present but we need to check if user has logged in successfully
if (loginBean == null) {
String contextPath = ((HttpServletRequest) request).getContextPath();
((HttpServletResponse) response).sendRedirect(contextPath + IUrlLocation.URL_LOGIN);
}
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
// Nothing to do here!
}
public void destroy() {
// Nothing to do here!
}
} |
Quand je clique sur "Déconnexion", obtiens l'erreur suivante, alors que si je mets un point d'arrêt dans la méthode lgout(), je ne m'y arrête pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
public class LoginFilter implements Filter {
/**
* Checks if user is logged in. If not it redirects to the login.xhtml page.
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Get the loginBean from session attribute
Utilisateur loginBean = (Utilisateur) ((HttpServletRequest) request).getSession().getAttribute("user");
// For the first application request there is no loginBean in the session so user needs to log in
// For other requests loginBean is present but we need to check if user has logged in successfully
if (loginBean == null) {
String contextPath = ((HttpServletRequest) request).getContextPath();
((HttpServletResponse) response).sendRedirect(contextPath + IUrlLocation.URL_LOGIN);
}
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
// Nothing to do here!
}
public void destroy() {
// Nothing to do here!
}
} |
Qqun a-t-il une idée du problème ?
Merci d'avance pour votre aide