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
Update Bean Property inside thread
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
Angular 2.4.5
- andyba
- Expert Member
- Posts: 2473
- Joined: 31 Mar 2011, 16:27
- Location: Steinfeld, near Bremen/Osnabrück, DE
- Contact:
@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.
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
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now
-
- Information
-
Who is online
Users browsing this forum: No registered users and 47 guests