PrimeFaces Push Faces消息通知不起作用

时间:2015-02-03 14:25:39

标签: jsf primefaces push-notification jsf-2.2

我对Push技术有疑问,项目是:

  • Primefaces 3.5
  • WebLogic 12c
  • Atmosphere Runtime 2.2

配置为:

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>cupertino</param-value>
</context-param>
<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>

观点:

@Named
@SessionScoped
public class FrmNotificacion  implements Serializable 
...
  public void send() {
    ...
       FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Usuario: "+getUser(), getMensajeDetalle());
       PushContext pushContext = PushContextFactory.getDefault().getPushContext();
       pushContext.push("/notificacion",  msg);
       System.out.println("......");
       FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

XHTML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui" >
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
        <title>Enivar Notificación</title>
    </h:head>
    <h:body>

        <h:form id="frmPrincipal" >
            <p:growl id="message" showDetail="true" />
            <p:panel header="Notificación" >
                <p:panelGrid columns="2" columnClasses="ui-widget-header,,ui-widget-header,,ui-widget-header,," >
                    <p:outputLabel  id="lblNombre"  value="Ingrese Usuario a Notificar:" />
                    <p:inputText id="txtNombre" value="#{frmNotificacion.user}" />
                    <p:outputLabel id="lblMensaje" value="Ingresar Mensaje Notificación" />
                    <p:inputTextarea id="txtMensaje" autoResize="true" value="#{frmNotificacion.mensajeDetalle}"/>
                </p:panelGrid>
                <p:commandButton id="btnNotifica"
                                 value="Notifica"
                                 update="message"
                                 actionListener="#{frmNotificacion.send()}"
                                 icon="ui-icon-arrowthickstop-1-e" />
            </p:panel>
        </h:form>

        <p:socket onMessage="handleMessage" channel="/notificacion"  />

        <script type="text/javascript">
            function handleMessage(msg) {
                msg.severity = 'info';
                grow.show([msg]);
            }
        </script>
    </h:body>
</html>

但是动作通知推送Faces消息无法正常工作

可能配置错误

它还向我展示了这个控制台:

INFO: Installed AtmosphereInterceptor Atmosphere LifeCycle with priority AFTER_DEFAULT 
03-feb-2015 9:09:50 org.atmosphere.cpr.AsynchronousProcessor action
ADVERTENCIA: Websocket protocol not supported
03-feb-2015 9:09:50 org.atmosphere.cpr.AsynchronousProcessor action
GRAVE: Invalid request state. AsyncContext#startAsync not supported. Make sure async-supported is set to true in web.xml   
03-feb-2015 9:09:52 org.atmosphere.cpr.AtmosphereFramework$4 run
INFO: Latest version of Atmosphere's JavaScript Client 2.2.6

1 个答案:

答案 0 :(得分:0)

更改JavaScript:

最后:

<script type="text/javascript">
        function handleMessage(msg) {
            msg.severity = 'info';
            grow.show([msg]);
        }
    </script>

对于此:

     <script type="text/javascript"> 
        function handleMessage(data) {
           alert("Hola");
        }
    </script>   

正如我那样,我在FacesMessage工作?