Update Bean Property inside thread

UI Components for JSF
Post Reply
Magesh
Posts: 1
Joined: 26 Nov 2014, 11:24

26 Nov 2014, 11:28

Hi,

I am new to Primefaces. I know that using update attribute or RequestContext.update method we can update the sepcific portion of the UI.

My requirement is when the page is loaded i will be invoking a thread which will fetch the data from DB till that time my UI will be displaying the spinning icon and right after it fetches the data i want to update the specific UI/widget portion.

I could see requestContext is null inside Thread.Please help me on this.Sample example will be pretty handy.

Regards,
Magesh

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

27 Nov 2014, 11:39

You should really read/try/study much more about requests, request cycles and threading. Short answer is that you can't do what you want because request scope isn't available in background thread. Simple way to accomplish this is to forget the threading and just block the page until the data is ready. If you want to have behavior like this you should have p:poll in your page. Then you use polling to check whether the thread has completed and when it has, you upgrade the desired portions of your page. And if you are using Java EE container (Wildfly, Glassfish, TomEE, etc) then you should not use threads directly but instead through @Asynchronous annotation. If what I said makes no sense, read at least relevant parts from Java EE tutorial.
PrimeNG 2.0.0
Angular 2.4.5

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

27 Nov 2014, 11:49

@Rikup: you need to learn more about how things like this can be and are actually done.

You can use PrimeFaces PUSH to do this.

Once the thread which is fetching the data is finished you can send a PUSH message to the specific user (hint: the channel name must be uniquely related to the user in question so that only they receive the message). The PUSH message handler can cause a remoteCommand to be called which then updates the page.

For details on how you can implement this you do need to check out the Showcase and the User Guide.
If you have more questions please feel free to ask them in this thread.

Rikup is right in that you do need to read up about Java Enterprise where this is relevant. There are excellent tutorials all over the place.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

01 Dec 2014, 11:05

@Andyba, I thought about push but I didn't write about it because I thought it might be overkill. But true, I was wrong here and it's simpler to go with push as you don't have to use two EJBs for messaging.
PrimeNG 2.0.0
Angular 2.4.5

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests