Spring-boot thymeleaf fragments: Exception evaluating SpringEL expression

1.8k views Asked by At

I'm facing a problem trying to get access in a ModelAndView from a thymeleaf fragment that shows a modal window.

This is my index.html:

<article th:each="girls : ${girlToRoot}" th:id="${girls.confirmcode}" class=" " data-status="1">
                    <img th:src="${girls.docProfile}" class="cover" th:alt="${girls.nickname}"/>
                        <a href="#" th:id="${girls.confirmcode}" onclick="callroom(this.id);" data-toggle="modal" data-target="#myModal">
                            <span class="protip favorite add" data-pt-width="900" data-pt-auto-hide="2000" data-pt-classes="favorite_protip" data-pt-gravity="right 5" data-pt-size="tiny" data-pt-trigger="sticky" data-pt-arrow="false">
                            <span class="broken-heart">
                                <i class="icon-heart-broken-left"></i><i class="icon-heart-broken-right"></i>
                            </span>
                            </span>
                            <span class="performer_name" th:text="${girls.nickname}">
                            </span>
                            <span class="badge vibratoy">&nbsp;</span>
                        </a>

                </article>

<th:block th:include="/fragments/modal/messageModal :: messageModal"/>

This is the fragment messageModal:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!--  Modal window to message  users -->
<th:block th:fragment="messageModal">

    <div id="myModal" class="modal fade">
        <div class="modal-body">
            <span class="close" id="close">Fechar ×</span>
            <th:block th:replace="/fragments/modal/show :: show"></th:block>
        </div>
    </div>
</th:block>
</html>

Here we have the fragment show as listed on the code above:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="show">
<input type="hidden" name="nickname" id="nickname" th:text="${girl.nickname}></input>
</html>

This is my js that makes a ajax to get the ModelAndView and opens the modal:

function callroom(room){

    $.ajax({
        type:"POST",
        url: "/getGirl",
        data: {confirmcode : room},
        cache: false,
        success: function(girl) {

        },
        error: function(response) {

        },
    });

    var messageModal = document.getElementById('myModal');
    var span = document.getElementById('close');
    messageModal.style.display = "block";

    span.onclick = function() {
        messageModal.style.display = "none";
        location.reload();

    }

}

And finaly my controller:

@RequestMapping(value = "/getGirl", method = RequestMethod.POST)
    @ResponseBody
    public GirlDataVM getGirl(Model model, @RequestParam("confirmcode") String room){

        GirlDataVM girlDataVM = new GirlDataVM();
        girlDataVM = girlService.getByConfirmCode(room);

        ModelAndView modelAndView = new ModelAndView();
        model.addAttribute("girl", girlDataVM);
        modelAndView.addObject("girl", girlDataVM);
        modelAndView.setViewName("/fragments/modal/show :: show");

        return girlDataVM;
    }

The problem is, i have to get the object girl into the modal show but i'm receiving the Exception evaluating SpringEL expression: "girl.nickname", if anyone can help me i'll be thank ...

1

There are 1 answers

2
Tanmoy Mandal On

you may try calling the getNickname() method instead of nickname