Problème d'authentification application j2EE
Bonjour,
Aider moi SVP toujours j'aurais " Compte Intouvable" lorsque je saisie le login et le mot de passe.
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
| @Stateless
@LocalBean
public class AdminService implements AdminServiceRemote, AdminServiceLocal {
@PersistenceContext
EntityManager entityManager;
public AdminService() {
}
@Override
public Administrateur authentAdmin(String login, String password) {
try{
Query query=entityManager.createQuery("select a from Administrateur where a.login=:login and a.password=:password").setParameter("login", login).setParameter("password", password);
return (Administrateur) query.getSingleResult();
}catch (Exception exception){
exception.printStackTrace();
return null;
}
} |
controller .java
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 30 31 32 33
| @ManagedBean
@RequestScoped
public class AuthentificationController {
Administrateur admin=new Administrateur();
@EJB
AdminServiceLocal adminServiceLocal;
private String login;
private String password;
public String authentificateAdmin(){
try {
if (adminServiceLocal.authentAdmin(login, password)!=null)
{
FacesContext.getCurrentInstance().getExternalContext().redirect("http://localhost:8383/ChangeWebb/faces/MenuTrigger.xhtml");
return"OK";
}else {
FacesMessage facesMessage =new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Compte introuvable");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
return "";
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
//getters & Setters |
code Xhtml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <p:panel id="id22" header="Authentification "/>
<p:panelGrid columns="2" >
<p:outputLabel value="Login "></p:outputLabel>
<p:inputText
value="#{authentificationController.login}" />
<p:outputLabel value="Password" />
<p:password value="#{authentificationController.password}"></p:password>
</p:panelGrid>
<p:commandButton value="S'authentifier" actionListener="#{authentificationController.authentificateAdmin()}" update="msgs"/>
<p:messages id="msgs" showSummary="true" showDetail="true" globalOnly="true"></p:messages> |