ZK with API Future

asked 2022-05-16 15:24:50 +0800

dgrenier gravatar image dgrenier

Is it possible to use API Future with ZK 9.6.1 ?

Example: Load some lists by calling Web Service:

    //.resolveTemplate("id", 20)
    .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
    .thenApply(response -> response.readEntity(new GenericType<List<Company>>() {} ) )
    .thenAccept(r -> updateCompanyList(r))

And update components in ZUL page (combobox):

    void updateCompanyList(Object data){
        listCompany = data

When I execute this code, I see the call to the Web Service, but nothing is loading in the combobox. Thanks for your help.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-17 15:05:46 +0800

MDuchemin gravatar image MDuchemin
2146 1 5
ZK Team

Based on your description, what probably happens is:

1 - ZK server receives the client's request (triggering your command) 2 - You start the future operation 3 - ZK server sends the response back to the client (without modifications, since nothing has changed at server side) 4 - the future operation is completed, and you call the updateCompanyList method as callback.

ZK will not automatically wait for async operations to finish before sending the response. If you want to update the UI after the async operation has taken place, you will need to enable server push.

Server push is a ZK feature that let the server initiate an execution (a transaction that updates the client). Usually, transactions are initiated by a user action at client-side (click on component, etc.). With server push, you can activate a desktop from server side directly and push an update to the client without having to wait on user activity.

See the server push documentation for more info.

Here's a simple example of how activating / deactivating desktops lets you update the client:


NOTE: The @smartNotifyChange might not work in that context. You may need to force a notifyChange on the VM field(s) that you need to push the the client after update. I recommend using the BindUtils.postNotifyChange option if you are doing this "in java code", since the annotations mostly expect default workflows.

Have a look, and let me know if that's what you are trying to do, or if you are encountering other issues.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2022-05-16 15:24:50 +0800

Seen: 11 times

Last updated: May 17

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More