Primefaces p:消息自动更新不起作用



我正在使用p:消息的自动更新属性,但它不工作,消息不出现在网页上。有趣的是,如果验证失败,则显示消息

样本——

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>
Java——

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;
}
 }        

但是如果我删除自动更新并使用以下功能,那么它就可以工作了-

<p:ajax event="click" listener="#{userweb.saveUser()}" update="msgs" />

我用的是-Primefaces 4.0JSF 2.2.6 (mojarra)Tomcat 7

请帮帮我.....谢谢

通过将JSF 2.2.6降级到JSF 2.2.2,一切都开始工作了。

相关内容

  • 没有找到相关文章

最新更新