Here’s my scenario:
I’m using JSF.
- I have a page that refreshes every 5 seconds (but the user doesn’t notice it because everything is ajaxified)
- I’d like to have a modal window that shows a list of things to the user when the user clicks something (e.g., a button). So every time the user clicks that button, the modal appears with the up to date list.
Right now I have the following: the modal with the a property loaded to it. This property loads stuff from DB and returns the list to the JSF page.
The main problem is since the page refreshes every 5 seconds, this property is called every 5 seconds (i.e., a request to DB).
Summarizing: I’d like to have a modal that loads a list every time the user clicks a button, inside a page that refreshes (ajaxified) every 5 seconds.
What’s the right way of doing such things? Pointers to good tutorials are good answers, I don’t need code, but rather understand the best practice.
Thanks.
I’d fetch the list from the database whenever the user clicks the button, and put it into a property of a bean that survives the current request (scope = session, view, conversation, or whatever), then bind that property with the EL expression.
To fetch the list upon clicking the button, have the button trigger an ajax request that rerenders the content of the panel, and makes the panel visible upon completion of the ajax request. You haven’t said what ajax or component library you are using; with Richfaces, it’s something like: