2017-01-04 10 views
0

モーダルウィンドウを表示するタイムリーフフラグメントからModelAndViewにアクセスしようとして問題が発生しました。Spring-bootyymeafフラグメント:SpringEL式を評価する例外が発生しました

これは私のindex.htmlである:ここでは上記のコードに記載されているとして、我々はフラグメントのショーを持っている

<!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> 

<!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> 

<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"/> 

これはフラグメントmessageModalです

これはModelAndViewを取得するためのajaxを作成し、モーダルを開くjsです:

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(); 

    } 

} 

そしてfinaly私のコントローラ:

@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; 
    } 

問題がある、私は、モーダルショーにオブジェクトの女の子を取得する必要がありますが、私はSpringEL式の評価の例外を受けています:「girl.nickname」を、誰もが私は...

+0

getNickname()メソッドを呼び出してみて、あなたのGirlDataVMクラスがgetNickname()メソッドを持っていますか? –

+0

ええ、方法はそこにあります。 –

答えて

0

に感謝するよ、私を助けることができる場合は、代わりにnickname

+0

まだ同じ問題です、オブジェクトの女の子は私がthを使用すると私のビューに来ていない:if = "$ {女の子}"入力が表示されません! –

+0

申し訳ありません私はあなたが言ったことを理解していませんでした。 in: "$ {girl!= null}"またはif: "$ {girl.getNickname()!= null}" とth:テキストのようなブール式を使用する必要がある場合は、これを試してください:text = "$ {girl.getNickname()}" –

関連する問題