Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1111527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:33:41+00:00 2026-05-17T02:33:41+00:00

When we create a JSF page, a client request allows generation of HTML dynamically

  • 0

When we create a JSF page, a client request allows generation of HTML dynamically using a combination of Java code and HTML.
Can we introduce hooks in the HTML page using JSF framework, that allow server to update the HTML page based on asynchronous events occurring later at the server, usually via different threads?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:33:41+00:00Added an answer on May 17, 2026 at 2:33 am

    JSF 2.3+

    You can use @Push and <f:websocket> for this. Below is a kickoff example with an applicaiton scoped socket which updates a data table upon an event fired by the backend via Event#fire() which the managed bean @Observes.

    <h:dataTable id="notifications" value="#{bean.notifications}" var="notification">
        <h:column>#{notification.message}</h:column>
    </h:dataTable>
    
    <h:form>
        <f:websocket channel="push">
            <f:ajax event="updateNotifications" render=":notifications" />
        </f:websocket>
    </h:form>
    
    @Named @ApplicationScoped
    public class Bean {
    
        private List<Notification> notifications;
    
        @Inject
        private NotificationService service;
    
        @Inject @Push
        private PushContext push;
    
        @PostConstruct
        public void load() {
            notifications = service.list();
        }
    
        public void onNewNotification(@Observes Notification newNotification) {
            notifications.add(0, newNotification);
            push.send("updateNotifications");
        }
    
        public List<Notification> getNotifications() {
            return notifications;
        }
    
    }
    
    @Stateless
    public class NotificationService {
    
        @Inject
        private EntityManager entityManager;
    
        @Inject
        private BeanManager beanManager;
    
        public void create(String message) {
            Notification newNotification = new Notification();
            newNotification.setMessage(message);
            entityManager.persist(newNotification);
            beanManager.getEvent().fire(newNotification);
        }
    
        public List<Notification> list() {
            return entityManager
                .createNamedQuery("Notification.list", Notification.class)
                .getResultList();
        }
    
    }
    

    JSF 2.2-

    If you’re not on JSF 2.3 yet, you need to head to 3rd party JSF libraries.

    • OmniFaces has <o:socket> (JSR356 WebSocket + CDI)
    • PrimeFaces had <p:socket> (Atmosphere)
    • ICEfaces had "ICEpush" (long polling)

    Noted should be that the <o:socket> was the basis for the JSF 2.3 <f:websocket>. So if you have found a lot of similarities, then that’s correct.

    PrimeFaces uses Atmosphere under the hoods (which is troublesome to setup without Maven). Atmosphere supports websockets with fallback to SSE and long polling. ICEfaces is based on ancient long polling technique. All of those do not implement native JSR356 WebSocket API which was only later introduced in Java EE 7.

    OmniFaces uses native JSR356 WebSocket API (supported in all Java EE 7 servers and Tomcat 7.0.27+). It is therefore also most simple to setup and use (one JAR, one context param, one tag and one annotation). It only requires CDI (not hard to install on Tomcat), but it enables you to even push from a non-JSF artifact on (e.g. a @WebServlet). For security and JSF view state keeping reasons, it only supports one-way push (server to client), not the other way round. For that you can keep using JSF ajax the usual way. The JSF 2.3 <f:websocket> is largely based on OmniFaces <o:socket>, hence you’ll find a lot of similarities in their APIs (JSF – OmniFaces).

    Alternatively, you can also use polling instead of pushing. Pretty much every ajax aware JSF component library has a <xxx:poll> component, such as PrimeFaces with <p:poll>. This allows you to send every X seconds an ajax request to the server and update the content whenever necessary. It’s only less efficient than push.

    See also:

    • How to monitor asynchronous/background thread status and get notifications in a JSF component
    • Real time updates from database using JSF/Java EE
    • Notify only specific user(s) through WebSockets, when something is modified in the database
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JSF's java classes to create UI elements for a simple HTML
Is there a way to create an html link using h:outputLink, other JSF tag
I created a web page that print some text using JSF I've added spaces
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I'm trying to create a new project using tomcat 7.0.27 + JSF 2.1.7 +
I am using a JSF 2.0 to create a web app (purely jee6, without
I try to create login form in web application. in JSP page I can
My goal is to present a jsf page that has Create, Retrieve and Update
I want to create JSF page which displays Oracle connections. The web page will
I want to create JSF page which displays Glassfish connections. The web page will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.