【问题标题】:Richfaces 4.1 and a4j:push: how to get it working?Richfaces 4.1 和 a4j:push:如何让它工作?
【发布时间】:2012-02-11 11:03:27
【问题描述】:

有人在像我这样的环境中使用 a4j:push 标签吗?

  • Richfaces 4.1-FINAL
  • MyFaces 2.1.5
  • 大气0.83
  • Tomcat 7.0.23

非常欢迎任何建议。

谢谢, 米洛·范德泽

这是我用来测试的:

web.xml(编辑:已修复):

...
<!-- Richfaces push servlet -->
<context-param>
    <param-name>org.richfaces.push.jms.disable</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>org.atmosphere.useBlocking</param-name>
    <param-value>true</param-value>
</context-param>
<filter>
    <filter-name>PushFilter</filter-name>
    <filter-class>org.richfaces.webapp.PushFilter</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>PushFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
    <param-name>org.richfaces.push.handlerMapping</param-name>
    <param-value>/__richfaces_push</param-value>
</context-param>
<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.richfaces.webapp.PushServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/__richfaces_push</url-pattern>
</servlet-mapping>
...

TestPushBean.java:

package com.vetmanager.base.test;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.apache.log4j.Logger;
import org.richfaces.application.push.MessageException;
import org.richfaces.application.push.TopicKey;
import org.richfaces.application.push.TopicsContext;

/**
 *
 */
@ManagedBean
@SessionScoped
public class TestPushBean {
    private static final Logger LOGGER = Logger.getLogger(TestPushBean.class.getName());

    private static final TopicKey TOPIC_KEY = new TopicKey("push");

    /**
     * Constructor init's the topic.
     */
    public TestPushBean() {
        LOGGER.debug("TestPushBean");

        TopicsContext topicsContext = TopicsContext.lookup();
        topicsContext.getOrCreateTopic(TOPIC_KEY);
    }

    /**
     * @return String
     */
    public String getNow() {
        LOGGER.debug("getNow");

        Calendar now = Calendar.getInstance();
        SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM-yyyy/HH:mm:ss");
        return dateFormatter.format(now.getTime());
    }

    /**
     * 
     */
    public void push() {
        LOGGER.debug("push");

        TopicsContext topicsContext = TopicsContext.lookup();
        try {
            topicsContext.publish(TOPIC_KEY, "Test String");
        } catch (MessageException e) {
            LOGGER.error("push: " + e, e);
        }
    }
}

和: test.xhtml:

<!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:a4j="http://richfaces.org/a4j"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
>

<h:head>
</h:head>

<h:body>
    <h:form>
        <a4j:push id="push" address="push" onerror="alert(event.rf.data)">
            <a4j:ajax event="dataavailable" render="now" execute="@none"/>
        </a4j:push>

        Tijd: <h:outputText id="now" value="#{testPushBean.now}"/><br/>

        <a4j:commandButton value="event" actionListener="#{testPushBean.push()}"/>
    </h:form>
</h:body>

</html>

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    此论坛帖子可能对使用 Servlets API 2.5 的人有用 (当您使用版本为 2.5 的 web.xml 时也会出现问题):

    https://community.jboss.org/message/647015#647015

    顺便说一句,您的具体问题可能是:

    将 Atmosphere 0.8.0-RC1 与 RichFaces 4.1.0.Final 一起使用,因为 Atmosphere 0.8.3 的 API 与 RC1 不兼容!

    否则我需要提供一些症状。

    【讨论】:

    • 非常感谢。这导致了一个有效的推送环境:)我将通过修复更新我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    相关资源
    最近更新 更多