update label on UI during long process

UI Components for JSF
Post Reply
fattanasio
Posts: 17
Joined: 23 Apr 2019, 10:16

09 Jun 2023, 12:57

Hello everyone,
I need to invoke a method that takes a long time, and I would like to update a label after each expected iteration in this lengthy method. How can I do that?
I am using PrimeFaces 11.
How to do this ? Thank you !

jepsar
Posts: 166
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

09 Jun 2023, 18:08

Please Google "jsf websocket".
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House

Noahsimpson
Posts: 1
Joined: 12 Jun 2023, 06:06

12 Jun 2023, 06:09

Wrap the long-running method within a separate method that will be called asynchronously.
Use the <p:remoteCommand> component from PrimeFaces to execute the lengthy method.
In the lengthy method, update the label's value using the PrimeFaces RequestContext class.

import org.primefaces.context.RequestContext;

// ...

public void lengthyMethod() {
for (int i = 0; i < expectedIterations; i++) {
// Perform the expected iteration logic here

// Update the label value
RequestContext.getCurrentInstance().addCallbackParam("currentIteration", i + 1);
}
}

fattanasio
Posts: 17
Joined: 23 Apr 2019, 10:16

12 Jun 2023, 14:11

Hello,
but the import org.primefaces.context.RequestContext cannot be resolved.
This is my pom.xml:

Code: Select all

<dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>11.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>${mojarra.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- JEE dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate-validator.version}</version>
        </dependency>

        <!-- CDI required APIs -->
        <dependency>
		    <groupId>javax.enterprise</groupId>
		    <artifactId>cdi-api</artifactId>
		    <version>2.0.SP1</version>
        </dependency>
        <dependency>
		    <groupId>org.apache.openwebbeans</groupId>
		    <artifactId>openwebbeans-jsf</artifactId>
		    <version>2.0.23</version>
        </dependency>



etc...

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

12 Jun 2023, 14:50

Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

fattanasio
Posts: 17
Joined: 23 Apr 2019, 10:16

12 Jun 2023, 15:48

jepsar wrote:
09 Jun 2023, 18:08
Please Google "jsf websocket".
I have enabled websocket in web.xml with:

Code: Select all

<context-param>
	     <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
	     <param-value>true</param-value>
	 </context-param>
and in managed bean with:

Code: Select all

@Inject @Push
private PushContext pushContext;
and in the xhtml:

Code: Select all

<f:websocket channel="pushContext" scope="view" onmessage="someWebsocketListener" />
but tomcat doesn't start. This is error:

"Multiple Endpoints may not be deployed to the same path"

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 42 guests