This question already has an answer here:
这个问题已经有了答案:
- h:messages does not display messages when p:commandButton is pressed 1 answer
- h:当按下命令按钮时,消息不会显示消息
I have a very simple problem but for the life of me I can't see where I'm going wrong. I have started to create a 'reset password' page with email and password inputs and a commandButton. Both input fields are required, but if I leave for example the password empty and click the button no message is displayed, and the server reports a warning:
我有一个很简单的问题,但我的一生都看不出哪里出了问题。我已经开始创建一个带有电子邮件、密码输入和命令按钮的“重置密码”页面。这两个输入字段都是必需的,但是如果我留下密码为空,并单击按钮,则不会显示任何消息,服务器将报告一个警告:
WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered. These unhandled FacesMessages are: - Please enter a new password
警告:有一些未处理的FacesMessage,这意味着不是每个FacesMessage都有机会被呈现。这些未处理的facesmessage是:-请输入新的密码
This is my page:
这是我的页面:
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<link type="text/css" rel="stylesheet" href="/css/main.css" />
<title>Request Password Reset</title>
</h:head>
<h:body>
<p:outputPanel layout="block" id="container">
<ui:include src="/header-branding-only.xhtml" />
<h3>
Reset Password
</h3>
<p:outputPanel id="content" layout="block">
<p>
<h:outputText value="Please enter your email address, a password of 8 characters or more and click 'Reset'." />
</p>
<h:form id="resetPasswordForm">
<p:panelGrid columns="2" styleClass="invisible-middlealign">
<p:panelGrid columns="2" styleClass="formatted" columnClasses="tdasheader, null">
<h:outputText value="Email Address" />
<p:inputText value="#{passwordResetBean.email}" size="40"
required="true" requiredMessage="Please enter your email address" />
<h:outputText value="New Password" />
<p:password value="#{passwordResetBean.password}" size="40"
required="true" requiredMessage="Please enter a new password" />
</p:panelGrid>
<p:commandButton value="Send" actionListener="#{passwordResetBean.resetPassword}" />
</p:panelGrid>
<h:messages style="color:red" />
</h:form>
</p:outputPanel>
<ui:include src="/footer.xhtml" />
</p:outputPanel>
</h:body>
</html>
and my backing bean:
和我的支持bean:
public PasswordResetBean() throws ApplicationException {
uuid = FacesUtil.getRequestParameter("uuid");
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void resetPassword(ActionEvent event) {
try {
boolean successful = securityService.resetPassword(email, password, uuid, userId);
if (successful) {
FacesUtil.getHttpSession(true).setAttribute("passwordReset", true);
FacesUtil.redirect(FacesUtil.getServletRequest().getContextPath()+"/logon.xhtml");
}
else {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage("The reset has failed. Please try again");
context.addMessage("resetPasswordForm", message);
}
}
catch (Exception e) {
handleException(e);
}
}
}
and faces config:
和脸配置:
<managed-bean>
<managed-bean-name>passwordResetBean</managed-bean-name>
<managed-bean-class>com.encounter.security.ui.PasswordResetBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>securityService</property-name>
<value>#{securityService}</value>
</managed-property>
</managed-bean>
Could someone please tell me where I'm going wrong?
谁能告诉我哪里出错了吗?
Thanks, Neil
谢谢,尼尔
2 个解决方案
#1
1
You need to update the h:messages
part after submitting the form, otherwise it is not possible to display any message there. I.e. use the following for the commandButton
提交表单后需要更新h:messages部分,否则不可能在那里显示任何消息。例如,对命令按钮使用以下命令
<p:commandButton update="resetPasswordForm" value="Send" actionListener="#{passwordResetBean.resetPassword}" />
#2
0
PrimeFaces messages can use autoupdate
PrimeFaces消息可以使用autoupdate
<p:messages id="messages" globalOnly="true" autoUpdate="true" closable="true" />
#1
1
You need to update the h:messages
part after submitting the form, otherwise it is not possible to display any message there. I.e. use the following for the commandButton
提交表单后需要更新h:messages部分,否则不可能在那里显示任何消息。例如,对命令按钮使用以下命令
<p:commandButton update="resetPasswordForm" value="Send" actionListener="#{passwordResetBean.resetPassword}" />
#2
0
PrimeFaces messages can use autoupdate
PrimeFaces消息可以使用autoupdate
<p:messages id="messages" globalOnly="true" autoUpdate="true" closable="true" />