我使用p:messages的autoUpdate属性,但它不起作用,网页上不会显示消息。有趣的是,如果valdation失败,则显示消息
样本 -
XHTML -
<h:form id="form_1">
<p:messages autoUpdate="true" showDetail="true" id="msgs" />
<table>
<tr>
<td>
<h:outputLabel id="label" style="width:100%" value="Name" />
</td>
<td>
<p:inputText id="text" value="#{userweb.bindUser.uname}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel id="label_1" style="width:100%" value="Pwd" />
</td>
<td>
<p:inputText id="text_1" value="#{userweb.bindUser.pwd}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel value=" " />
</td>
<td>
<p:commandButton id="button" value="Save" validateClient="true">
<p:ajax event="click" listener="#{userweb.saveUser()}" />
</p:commandButton>
</td>
</tr>
</table>
</h:form>
ui.xhtml -
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" template="base.xhtml">
<ui:define name="body">
<h:body>
<ui:include src="bodyMain.xhtml" />
<div id="container">
<div id="header" class="ui-widget ui-widget-header">
<ui:include src="header.xhtml" />
</div>
<div id="page" class="ui-widget">
<div id="nav">
<ui:include src="\leftmenu.xhtml">
<ui:param name="menuItem" value="#{impaktNavigator}"></ui:param>
</ui:include>
</div>
<div id="content">
<ui:insert name="content">...</ui:insert>
</div>
</div>
<div class="clearfooter"></div>
</div>
<div id="footer" class="ui-widget ui-widget-header ui-corner-all">
<p>Running on Impakt 1.1</p>
</div>
</h:body>
</ui:define>
base.xhtml -
<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">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
<title>Demo</title>
</f:facet>
<h:outputStylesheet library="css" name="application.css" target="head" />
</h:head>
<ui:insert name="body"></ui:insert>
</f:view>
</html>
爪哇 -
package webmodule;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import model.User;
import org.omnifaces.util.Faces;
import org.springframework.beans.factory.annotation.Autowired;
public class Userweb implements Serializable
{
User bindUser;
@Autowired
public void setBindUser(User bindUser) {
this.bindUser = bindUser;
}
public User getBindUser() {
return bindUser;
}
public void saveUser() throws Exception {
String result = null;
FacesMessage msg = new FacesMessage("Done", "It worked");
FacesContext.getCurrentInstance().addMessage(null, msg);
//return result;
}
}
但是,如果我删除autoUpdate并使用以下,那么它可以工作 -
<p:ajax event="click" listener="#{userweb.saveUser()}" update="msgs" />
我正在使用 - Primefaces 4.0 jsf 2.2.6(mojarra) Tomcat 7
Plz帮帮我.....谢谢
答案 0 :(得分:0)
通过将JSF 2.2.6降级为JSF 2.2.2,一切都开始起作用。