JSF 2.3не работает на Wildfly 15.0.0 - PullRequest
1 голос
/ 14 марта 2019

Я пытаюсь сделать простой пример JSF с использованием функции для обновления содержимого страницы.К сожалению, он работает только после самого первого развертывания или после перезапуска сервера.

Если я пытаюсь повторно развернуть приложение, все вызовы push нажимаются, и на веб-странице и на странице сети не происходит никаких обновлений.инструментов разработчика Я вижу много повторяющихся запросов типа 'websocket' с кодом 101 Протокол коммутации .

Кроме того, я вижу эту ошибку в журнале сервера, если яя пытаюсь остановить это

11:59:31,444 ERROR [org.jboss.weld.Bean] (ServerService Thread Pool -- 100) WELD-000019: Error destroying an instance com.sun.faces.push.WebsocketChannelManager$ViewScope@ff2ea8c of Managed Bean 
[class com.sun.faces.push.WebsocketChannelManager$ViewScope] with qualifiers [@Any @Default]

Скорее всего, веб-сокеты, созданные JSF, не уничтожены правильно, но я не могу выяснить, почему это произошло.

Мой именованный код компонента

@Named
@ApplicationScoped
public class Bean implements Serializable {

    private static Logger logger = LoggerFactory.getLogger(Bean.class);

    private List<Message> notifications;

    @Inject
    @Push
    private PushContext viewPush;

    @PostConstruct
    public void load() {
        notifications = new ArrayList<>();
    }

    public List<Message> getNotifications() {
        logger.info("Get notifications {}", notifications.size());
        return notifications;
    }

    public void sendPush() {
        notifications.add(new Message("!!!"));
        viewPush.send("newMsg");
    }

    public static class Message {

        private String text;

        public Message(String text) {
            this.text = text;
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    }
}

index.xhtml

<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
>

<h:head>
    <title>Primefaces product List</title>
</h:head>

<h:body>

    <h:form>
        <h:dataTable id="notifications" value="#{bean.notifications}" var="notification">
            <h:column>
                <f:facet name="header">Text</f:facet>
                #{notification.text}
            </h:column>
        </h:dataTable>

        <h:commandButton action="#{bean.sendPush}" value="Send push">
            <f:ajax/>
        </h:commandButton>

        <f:websocket channel="viewPush">
            <f:ajax event="newMsg" render="notifications"/>
        </f:websocket>
    </h:form>

</h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <display-name>Archetype Created Web Application</display-name>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>faces-servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>faces-servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

  <context-param>
    <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
    <param-value>true</param-value>
  </context-param>
</web-app>

У меня есть эти зависимости в pom.xml

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-jsf</artifactId>
        <version>15.0.0.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0.SP1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
        <scope>provided</scope>
    </dependency>
...