Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OmniFaces WebSocket demo #490

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
package org.primefaces.showcase.view.ajax;

import jakarta.annotation.PostConstruct;
import jakarta.faces.push.Push;
import jakarta.faces.push.PushContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.io.Serial;
import java.io.Serializable;

import io.quarkus.logging.Log;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.jbosslog.JBossLog;
import org.omnifaces.cdi.Push;
import org.omnifaces.cdi.PushContext;

@Named
@ViewScoped
@JBossLog
public class WebSocketView implements Serializable {

@Serial
Expand Down Expand Up @@ -71,7 +72,7 @@ public void init() {
}

public void sendMessage() {
Log.infof("Sending message: %d", count);
log.debugf("Sending message: %d", count);
pushChannel.send("quarkusMessage");
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/resources/META-INF/resources/ui/ajax/websocket.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
xmlns:ui="jakarta.faces.facelets"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:p="primefaces"
xmlns:o="http://omnifaces.org/ui"
template="/template/template.xhtml">

<ui:define name="title">
Ajax Framework <span class="subitem">WebSocket</span>
</ui:define>

<ui:define name="description">
WebSocket allows server side push events.
WebSocket allows server side push events using OmniFaces <code>o:socket</code>. Faces
<code>f:websocket</code> is not currently working
due to an open MyFaces defect: <a href="https://issues.apache.org/jira/projects/MYFACES/issues/MYFACES-4685"
rel="noopener" target="_blank">MYFACES-4685</a>
</ui:define>

<ui:define name="implementation">
<div class="card">
<h:form id="frmSocket">
<f:websocket scope="view" channel="pushChannel" onmessage="function(m){console.log(m);}">
<o:socket scope="view" channel="pushChannel" onmessage="function(m){console.log(m);}">
<f:ajax event="quarkusMessage" render="frmSocket:txt_count"/>
</f:websocket>
</o:socket>
<h1 class="text-center">
<h:outputText id="txt_count" value="#{webSocketView.count}"/>
</h1>
<p:commandButton value="Test" actionListener="#{webSocketView.sendMessage()}" process="@this"/>
</h:form>
</div>
</ui:define>
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/META-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<param-name>jakarta.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>jakarta.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
Expand Down Expand Up @@ -122,6 +118,10 @@
</context-param>

<!-- Context parameters - OmniFaces -->
<context-param>
<param-name>org.omnifaces.SOCKET_ENDPOINT_ENABLED</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.COMBINED_RESOURCE_HANDLER_DISABLED</param-name>
<param-value>#{facesContext.application.projectStage eq 'Development'}</param-value>
Expand Down Expand Up @@ -226,4 +226,4 @@
<extension>svg#fontawesomeregular</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
</web-app>
</web-app>