简体   繁体   中英

thymeleaf block is not show when condition of th:if is true

i have a block in here:

<th:block th:if= "${not #lists.isEmpty(listGuide)}">
                <table class="table" style="margin-left: 100px" >
                    <thead>
                        <tr>
                            <td><b>Tên</b></td>
                            <td><b>Địa chỉ</b></td>
                            <td><b>Phone</b></td>
                            <td><b>Kinh nghiệm</b></td>
                        </tr>
                    </thead>
                </table>
                </th:block>

and controller is

@PostMapping("/operator/search")
public String searchGuide(HttpServletRequest request, Model model) {
            String location = request.getParameter(Constant.PARAMETER_LOCATION);
            String language = request.getParameter(Constant.PARAMETER_LANGUAGE);
            String gender = request.getParameter(Constant.PARAMETER_GENDER);
            String type = request.getParameter(Constant.PARAMETER_TYPE);
            model.addAttribute("listGuide",
                    operatorService.findGuide(location, gender, type, language));
            log.info("size list guide search: "
                    + operatorService.findGuide(location, gender, type, language).size());
            return Constant.VIEW_REDIRECT_FIND_GUIDE;
}

this log " size list guide search: 19901" but block not show. Why? anyone help me?

UPDATE VIEW_REDIRECT_FIND_GUIDE is

public static final String VIEW_REDIRECT_FIND_GUIDE = "redirect:/operator/searchguide";

and controller of /operator/searchguide is:

public String findGuide(HttpServletRequest request, Model model) {
            Principal principal = request.getUserPrincipal();
            User user = userDetailService.findByUsername(principal.getName());
            Operator operator = operatorService.findByUserId(user.getId());
            model.addAttribute(Constant.ENTITIY_OPERATOR, operator);
            model.addAttribute(Constant.ENTITIY_LIST_LANGUAE, (List<Language>) languageService.findAll());
            model.addAttribute(Constant.ENTITIY_LIST_LOCATION, (List<Location>) locationService.findAll());
            return "find-guider";

As I said in my previous comment you have to use Flash Scope since you are redirecting to a page. Try something like below

@PostMapping("/operator/search")
public String searchGuide(HttpServletRequest request, RedirectAttributes attributes) {
            String location = request.getParameter(Constant.PARAMETER_LOCATION);
            String language = request.getParameter(Constant.PARAMETER_LANGUAGE);
            String gender = request.getParameter(Constant.PARAMETER_GENDER);
            String type = request.getParameter(Constant.PARAMETER_TYPE);
            //model.addAttribute("listGuide", operatorService.findGuide(location, gender, type, language));
            attributes.addFlashAttribute("listGuide",peratorService.findGuide(location, gender, type, language));
            log.info("size list guide search: "
                    + operatorService.findGuide(location, gender, type, language).size());
            return Constant.VIEW_REDIRECT_FIND_GUIDE;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM