2

I'm using Spring Boot and Thymeleaf and I'm a bit confused about finding best solution. On back-end side, I got sheduled function that is sheduled several times a day, and each time it updates my Boolean success; flag to true if everything went fine, or false otherwise.

So lets begin with Controller

@Controller
public class MyController {
    @Autowired
    Flags flags;

    @RequestMapping("/home")
    public String function(Model model) {
        model.addAttribute("isSuccess", flags.isSuccess());
        return "home";
    }   
}

div I want to update

<div class="alert alert-success" th:if="${isSuccess}">
    Success
</div>

Once app starts, its not displayed, as I want. But then I'm sheduling few tasks

@Service
public class MyService {

    @Autowired
    Flags flags;

    public mySheduledFunction() {
        //... do stuff and if ok
        flags.setSuccess(true);
    }    
}

@Component
public class Flags {
    private Boolean success;

    public void setSuccess(Boolean param){
        success = param;
    }

    public Boolean isSuccess() {
        return success;
    }
}

Now here is the part I have problem with, function ends up successfully, but to see my div rendered, I need to manualy refresh page, which obviously is not the solution I want. So what would be the best solution to refresh page or single div from back-end?

user9309329
  • 313
  • 3
  • 13

0 Answers0