问题
How would I go about updating a UI component when a server process finishes or anytime else for that matter?
Can\Should I
- extend the UI component and register some kind of EventListener on it?
- bind the UI component in a backing bean?
- use some of the new PrimePush features?
- something else?
If anyone could guide me in the right direction I'd appreciate it.
Example Case One
Server process ends and updates the database.
I want to automatically update a DataTable with new rows based on the new information.
I don't want to poll for the new data.
EDIT
I want to update the UI component (a primefaces datatable) from an EJB Stateless Bean
回答1:
You didnt mention which version of primefaces you are using but you can update components from backed bean with addpartialupdatetarget.
RequestContext context = RequestContext.getCurrentInstance();
context.addPartialUpdateTarget("myForm:myComponent");
回答2:
You can just use the update attribute of your commandButton or whatever else you're using.
Something like this should work
<p:dataTable value="#{backer.bean}" id="table">
// columns with data
</p:dataTable>
<p:commandButton actionListener="#{backer.updateDB}" update="table" />
来源:https://stackoverflow.com/questions/11656415/update-ui-components-from-server-event