Search code examples
spring-bootthymeleafcordaspring-webflux

How to display data from Flux in Thymleaf + springboot controller


I'm trying to display Progress tracker information received from a Corda node. I'm using ReactiveDataDriverContextVariable set as an attribute to the model of a controller in Springboot controller/ Thymeleaf, but it doesn't work, it is only displaying the address of my variable.

I've tried the tutorial from this site

My controller looks like (I manage to create a Flux from Progresss tracker observable, myFlux)

    public String index(final Model model) {

        // loads 1 and display 1, stream data, data driven mode.
        IReactiveDataDriverContextVariable reactiveDataDrivenMode =
                new ReactiveDataDriverContextVariable(myFlux, 100);

        model.addAttribute("progressTracker", reactiveDataDrivenMode);

        return "index";

    }

My thymleaf view

        <table id="Progress" class="table table-striped">
            <thead>
            <tr>
                <th width="70%">Step</th>
            </tr>
            </thead>
            <tbody>
            <tr class="result" data-th-each="step: ${progressTracker}">
                <td>[[${step}]]</td>
            </tr>
            </tbody>
        </table>

Solution

  • When you say "displaying the address of my variable", I belive its the hash object hash you are referring to which is being printed because of the absence of a proper toString() method.

    I believe you are trying to print the observable rather than subscribing to it. For example, when you do below, it doesn't do much as you are trying to print the observable.

    val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
    println(handle.progress);
    

    What you should actually be doing is this:

     val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
     handle.progress?.subscribe {
          println(it)
     }
    

    It should print the progress steps.