Bonjour,
j'ai développer une page d'authentification (login et mot de passe)...j'ai utilisé postgres comme sgbd..le problème et que tourne null dans la méthode validation ...toujours rediriger vers la page erreur
voici mon code
code page acceuil.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
Login: <h:inputText value="#{bonjourManagedBean.identifiant}"></h:inputText>
<br></br>
<br></br>
Password:<h:inputText value="#{bonjourManagedBean.pwd}"></h:inputText>
<br></br> <br></br>
<h:commandButton value="Valider" action="#{bonjourManagedBean.validerUtilisateur()}" ></h:commandButton>
</h:form>
</h:body>
</html>
classe bean:
/*
* 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 Com.fst.beans;
import Com.fst.controller.UtilisateurJpaController;
import Com.fst.entities.Utilisateur;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.UserTransaction;
/**
*
* @author pole
*/
@Named(value = "bonjourManagedBean")
@SessionScoped
public class BonjourManagedBean implements Serializable {
private UserTransaction utx;
private EntityManagerFactory emf;
private String identifiant;
private String pwd;
private UtilisateurJpaController utilisateurJpaController;
public String getIdentifiant() {
return identifiant;
}
public void setIdentifiant(String identifiant) {
this.identifiant = identifiant;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public BonjourManagedBean() {
}
@PostConstruct
private void init()
{
try{
emf=Persistence.createEntityManagerFactory("BonjourFSTPU");
utx=(UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
utilisateurJpaController = new UtilisateurJpaController(utx,emf);
}
catch(NamingException ex)
{
Logger.getLogger(BonjourManagedBean.class.getName()).log(Level.SEVERE, null ,ex);
}
}
public void validerUtilisateur()
{
Utilisateur utilisateur=utilisateurJpaController.findUtilisateur("ala");
if(utilisateur != null)
{
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "/faces/fst/bienvenue.xhtml?faces-redirect=true");
}
else
{ FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "/faces/fst/erreur.xhtml?faces-redirect=true");
}
}
}
Afficher la suite