lundi 22 juin 2015

JSF message won't appear in tab

i'm new to JSf framework, am trying to work on a login page example. The problem is that the message for mail validation won't appear in the right place despite i add it inside the form.

Here is the source code for the entire web page :

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb"
      xmlns:h="http://ift.tt/J1LPWj"
      xmlns:p="http://ift.tt/HjFrZc">
    <h:head>
    <title>Quiz creator </title>
    <h:outputStylesheet library="default" name="ressources/css/style.css"/>

</h:head>
<h:body >

    <p:layout fullPage="true">
        <p:layoutUnit position="center" >
            <p:accordionPanel multiple="true" activeIndex="0">
                <p:tab title="Se connecter" >
                    <h:form id="connection">
                        <h:outputText value=" Adresse email" />
                        <br />
                        <p:inputText id="mail" value="#{login.mail}" requiredMessage="Veuillez saisir votre mail "></p:inputText>
                        <!--                                this is the message from the bean for mail field-->
                        <p:message for="mail"></p:message>
                        <br />
                        <br />
                        <h:outputText value=" Mot de passe " />
                        <br />
                        <p:inputText id="pwd" type="password" value="#{login.pwd}"></p:inputText>
                        <h:message for="pwd" style="color:red"></h:message>
                        <br /><br />
                        <p:commandButton value="OK" icon="ui-icon-circle-check" action="#{login.validateMailPaswword()}" ajax="false"></p:commandButton>
                    </h:form>
                </p:tab>
                <p:tab title="S'inscrire">
                    <h:form>
                        <h:outputText value=" Nom " />
                        <br />
                        <p:inputText id="nom"></p:inputText>
                        <br />
                        <h:outputText value=" Prenom " />
                        <br />
                        <p:inputText id="prenom"></p:inputText>
                        <br />
                        <h:outputText value="  Adresse email "/>
                        <br />
                        <p:inputText id="mail"></p:inputText>
                        <br />
                        <h:outputText value=" Mot de passe " />
                        <br />
                        <p:inputText id="pwd" type="password"></p:inputText>
                        <br />   <br />             
                        <p:button value="Confirmer" icon="ui-icon-circle-check" ></p:button>
                    </h:form>
                </p:tab>
                <p:tab title="Comment ça marche ? " closable="true">
                    Vous êtes curieux, vous aimez les challenges, les quizs, c'est l'endroit parfait pour en s'assurer  ...
                    mais comment ?
                    <br/><br/>
                    <ul type="circle">
                        <li>Publier vos propres quizzs</li>
                        <li>Résoudre les quizzs des autres, et gagnez plus de points !</li>
                    </ul>
                </p:tab>

            </p:accordionPanel>

        </p:layoutUnit>
        <p:layoutUnit position="west" size="550" header="Bienvenue à tous !" collapsible="true" footer="">
            <h:graphicImage value="ressources/images/think.jpg"></h:graphicImage>
        </p:layoutUnit>
    </p:layout>
    <h:link outcome="welcomePrimefaces" value="Primefaces welcome page"/>
    <br />
</h:body>

and here is the source code of the bean in charge of sending the message :

package com.ham.jsf.beans;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Hamza
 */

@ManagedBean
@SessionScoped
public class Login {
    private String mail;
    private String pwd;
    private String msg;
public String getPwd() {
    return pwd;
}

public void setPwd(String pwd) {
    this.pwd = pwd;
}

public String getMail() {
    return mail;
}

public void setMail(String mail) {
    this.mail = mail;
}

public String getMsg() {
    return msg;
}

public void setMsg(String msg) {
    this.msg = msg;
}

public String validateMailPaswword() {
    int x = 1;
        //1 here is for test if mail exist or not for later use
    if (x == 0) {
        return "admin";
    } else {
        FacesContext.getCurrentInstance().addMessage("connection:mail", new FacesMessage(FacesMessage.SEVERITY_WARN, "Mail invalide",
                "Vérifier le mail"));
        //x=1  so i raised a message 
        return "login";
    }
}

}

The message is shown like this :

enter link description here

Any help please

Aucun commentaire:

Enregistrer un commentaire