我正在使用 primefaces 实现登录表单,但未显示我的消息,可能是什么?
我尝试使用 id 字段或在方法 addMessage() 中传递 null。
我的 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://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>
我的豆子:
@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";
}
}
谁能告诉我出了什么问题?他返回登录页面,但没有显示消息。