Dawid Skrzypczyński
Dawid Skrzypczyński

Reputation: 311

JSF and applicationscoped bean connection(Publish/Subscribe)

I want to create simple web application which will be work similarly to publish/subscribe mechanism. I have applicationScoped bean that contains list of strings and xhtml where i display this strings as a table. Now i want to add something like listener and when list of string in applicationScoped bean will change my table also should change. How can i achieve this ?

Upvotes: 1

Views: 181

Answers (1)

noone
noone

Reputation: 19796

Actually the table will change automatically. If you press F5 on the page with the table you will notice that the new entries will be rendered now. In the render-phase of JSF it will process the data behind the value attribute of your table again.

But I assume you do not want the user to press F5, but some other solution.

The easiest would be a button to refresh the table with some ajax like this:

<h:commandButton value="Refresh" immediate="true">
    <f:ajax render="tableComponent" />
</h:commandButton>

This is a clumsy approach, but it shows that all that needs to be done is re-render the table.

Using some 3rd party libraries you might also do this automatically. Using RichFaces you may use <a4j:push>. In PrimeFaces you can use PrimePush. Both internally use the Atmosphere framework. The links will show you how to use them to automatically push the list-has-changed-event from the server to the client (browser).

Upvotes: 1

Related Questions