2016-09-30 45 views
0

エラーが発生しました:プロパティまたはフィールド 'datas'がthymeleafのヌルに見つかりません。Thymeleafプロパティまたはフィールド 'datas'がnullに見つかりません

私は同様の問題を抱えていますが、私のコードで問題が見つかりません。

基本的には、Name(String)とDates(List)という2つの属性を持つMonthsという名前のオブジェクトとリストがあります。

ここでコントローラ

@PostConstruct 
    public void inicializar() { 
     System.out.println("INICIALIZANDO...");    
     months = DrawCalendarTable.calendarTable(2016); // list of object 'months' with name and list of dates as string 
     for(Months month : months){ 
      System.out.println(month.toString()); //just for test... print the data i want correctly 
     } 
    } 

    @RequestMapping("/calendario") 
    public ModelAndView listar(){ 
    ModelAndView mv = new ModelAndView("calendarTable");   
    mv.addObject("listOfMonths", months); 
    return mv; 

そして、ここで私は、オブジェクトの月のフィールドのための適切なgetメソッド持つHTML

<table class="table table-striped table-bordered" 
        style="vertical-align: center"> 
        <thead> 
         <tr> 
          <th>Nome</th> 
          <th th:each="months : ${listOfMonths}" th:text="${months.name}">months</th> <!-- This works just fine. Also, if i use ${months.datas} it also works-->               
          <!-- Lista de Meses --> 
         </tr> 
        </thead> 
        <tbody> 
         <tr> 
          <!-- Lista Funcionarios --> 
          <td th:text="Anderson">Anderson</td>         
          <td > 
           <table class="table table-bordered"> 
            <tr th:each="days : ${months.datas}"> <!-- Here, months.data does not work. ERROR: CANNOT BE FOUND ON NULL--> 
             <td th:text="F"></td> 
             <!-- Desenha celulas de dia, de acordo com o mes --> 
            </tr> 
           </table> 
          </td> 
         </tr> 
        </tbody> 
       </table> 

です:

public List<String> getDatas() { 
    return datas; 
} 

答えて

0

オブジェクトをモデルに追加した名前は "listOfMonths"です。あなたのモデルには「月」という名前のオブジェクトはありませんので、次の行に到達したときにこの行に到達したとき:

<tr th:each="days : ${months.datas}"> 

月がnullです。トップラインは、使用する前に「月」を定義しているため動作します。

th:each="months : ${listOfMonths}" 
+0

私は 'months:$ {listOfMonths}'をしていますが、このオブジェクトはmonths.nameとmonths.datasとして持っていませんか? 「月:each:」日:$ {months.datas} 'は以前のものと同じオブジェクトではありませんか? –

+0

の「月」はタグ自体との内部に表示されます。再度使用する場合は、後で変数を再定義してください。 – Metroids

関連する問題