Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update PrimeFaces dataTable from backing bean

Tags:

jsf

primefaces

I use schedule(Timer) in bean which update variable when employees enrolling which get data from fingerprint device. I need to update component in jsf from backing bean when variable in bean updated. I try to use primefaces poll component but it update component every time.

like image 368
Guwanch Avatar asked Oct 03 '13 12:10

Guwanch


4 Answers

Assuming you'll be calling a Java method using Listener from Fingerprint device API, and from ManagedBean you can update any Primefaces Component using RequestContext.

RequestContext.getCurrentInstance().update("ID_OF_YOUR_DATATABLE")
like image 52
Kishor Prakash Avatar answered Nov 16 '22 00:11

Kishor Prakash


There's already a component in Primefaces, as you can see : here.

RequestContext is a feature with various handy utilities.

Update component(s) programmatically. Execute javascript from beans. Add ajax callback parameters. ScrollTo a specific component after ajax update.

Have a look here for an example.

like image 40
Ioan Avatar answered Nov 15 '22 23:11

Ioan


I resolved my problem with primefaces push component.

java code is:

 PushContext pushContext = PushContextFactory.getDefault().getPushContext();
  pushContext.push("/finger", "Pressed"); 

in jsf:

<p:socket channel="/finger" onMessage="clearCookies" /> 

"clearCookies" is remoteCommand function which update my dataTable.

like image 41
Guwanch Avatar answered Nov 15 '22 23:11

Guwanch


It has changed from primefaces 7.0

PrimeFaces.current().ajax().update("elementJS");
like image 33
manelseo Avatar answered Nov 16 '22 00:11

manelseo