primefaces-Nachricht funktioniert nicht

Ich die Umsetzung ein login-Formular mit primefaces, aber meine Nachrichten werden nicht angezeigt, was kann das sein?

Habe ich versucht, mit dem id-Feld oder übergeben von null in der Methode addMessage ().

mein xhtml code:

<?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://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>
          Wellcome<br/>
        <h:form id="login">
            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
            <p:growl id="msg" showDetail="true" life="3000" />
            <p:panel header="Login" style="width: 360px;">
                <h:panelGrid id="loginPanel" columns="2">
                <h:outputText value="Email:" for="email" />
                <p:inputText id="email" value="#{loginBean.email}" ></p:inputText>
                <p:spacer></p:spacer>
                <p:message for="email" />

                <h:outputText value="Senha" for="senha" />
                <p:password id="senha" value="#{loginBean.senha}"  feedback="false" minLength="1"></p:password>
                <p:spacer></p:spacer>
                <p:message for="senha" />
                <p:spacer></p:spacer>
                <p:commandButton action="#{loginBean.loginAction}" value="Login" update="loginForm" ajax="true"></p:commandButton>
            </h:panelGrid>
            </p:panel>
        </h:form>
    </h:body>
</html>

meine Bohne:

@ManagedBean
@RequestScoped
public class LoginBean {

    private static final long serialVersionUID = 1L;
    private String email;
    private String senha;

    @ManagedProperty(value="#{usuarioSessionBean}")
    private UsuarioSessionBean usuarioSessao;

    public String loginAction()
    {
        //Valida preenchimento dos campos de email e senha
        boolean campoBranco = false;
        if((email == null) || (email.trim().length() == 0))
        {
            campoBranco = true;
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, "Email não informado!","Preencha o email e tente novamente!"));
        }

        if((senha == null) || (senha.trim().length() == 0))
        {
            campoBranco = true;
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, "Senha não informada!","Preencha a senha e tente novamente!"));
        }

        if(campoBranco)
            return "login";
    }
}

Kann mir jemand sagen was falsch ist? Er kehrt zurück auf die login-Seite, aber nicht die Nachrichten.

  • Versuchen Sie, ändern Sie Ihre Methode, um public String loginAction(ActionEvent actionEvent)
  • Ich änderte die Methode, wie Sie Ihre Empfehlung und die Befehlsschaltfläche meiner xhtml<p:commandButton action="login" value="Login" update="loginForm" ajax="true" actionListener="#{loginBean.loginAction}"/>). Aber nicht funktionieren.
InformationsquelleAutor user1352652 | 2013-04-26
Schreibe einen Kommentar