简体   繁体   中英

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 ?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM