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 !
update label on UI during long process
Please Google "jsf websocket".
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
-
- Posts: 1
- Joined: 12 Jun 2023, 06:06
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);
}
}
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);
}
}
-
- Posts: 17
- Joined: 23 Apr 2019, 10:16
Hello,
but the import org.primefaces.context.RequestContext cannot be resolved.
This is my pom.xml:
etc...
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...
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
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
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
-
- Posts: 17
- Joined: 23 Apr 2019, 10:16
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>
Code: Select all
@Inject @Push
private PushContext pushContext;
Code: Select all
<f:websocket channel="pushContext" scope="view" onmessage="someWebsocketListener" />
"Multiple Endpoints may not be deployed to the same path"
-
- Information
-
Who is online
Users browsing this forum: No registered users and 42 guests