2016-10-30 4 views
0

私は以下のオブジェクトを持っています。リスト項目をチェックボックスとして表示 - BindingResultもプレーンも利用できません

public class Anonymization { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private long id; 
    @OneToMany(mappedBy = "anonymization") 
    private List<Host> hosts; 
    @OneToMany(mappedBy = "anonymization") 
    private List<Item> items; 

オブジェクトHostItemは、いくつかのブールフィールドを持っています。私はすべてのホストとアイテムオブジェクトがチェックボックスとして表示されるフォームを表示して、ブールフィールドを編集できるようにしたい。私は、フォーム

@RequestMapping("monitoringsystem/{mId}/anonymization") 
    public String editAnonymisatzion(Model model, @PathVariable Long mId){ 
     model.addAttribute("mId", mId); 
     model.addAttribute("anonymization", monitoringSystemRepository.findOne(mId).getAnonymization()); 
     return "monitoringsystem/anonymizationForm"; 
    } 

anonymizationFormがでチェックボックスを表示する必要がありますを表示するには、コントローラを書いたため、各ループ残念ながら、私は次のようなエラー

を得ているビューを呼び出すとき

<!-- more code ---> 
<form class="form-horizontal" th:modelAttribute="anonymization" th:object="${anonymization}" th:action="@{'monitoringsystem/' + ${mId} + '/anonymisatzion/save'}" method="post"> 
      <input type="hidden" th:field="*{id}"/> 
      <fieldset> 
       <legend>Set Anonymization</legend> 
       <div class="panel panel-default"> 
        <div class="panel-heading">Anonymizie Hostnames</div> 
        <div class="panel-body"> 
         <div class="form-group" th:each="host : ${anonymization.hosts}"> 
          <label class="col-md-4 control-label" for="checkboxes" th:text="${host.name}"></label> 
          <div class="col-md-4"> 
           <div class="checkbox"> 
            <label for="checkboxes-0"> 
             <input th:field="${host.anonymizeName}" type="checkbox" /> 
             anonymizie 
            </label> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="panel panel-default"> 
        <div class="panel-heading">Anonymizie Items</div> 
        <div class="panel-body"> 
         <div class="form-group" th:each="item : ${anonymization.items}"> 
          <label class="col-md-4 control-label" for="checkboxes" th:text="${item.name}"></label> 
          <div class="col-md-4"> 
           <div class="checkbox"> 
            <label for="checkboxes-0"> 
             <input th:field="${item.anonymizeName}" type="checkbox" /> 
             anonymizie name 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label for="checkboxes-0"> 
             <input th:field="${item.anonymizeData}" type="checkbox" /> 
             anonymizie data 
            </label> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
<!-- more code ---> 

Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'host' available as request attribute 

私のデータベースをチェックするすべてのリレーションシップが正しく設定されています。 List<Host>には1が、List<Item>には2つのエントリが含まれている必要があります。

私は間違いを見つけられません。

UPDATE 1:

Iは、フォームに渡される匿名オブジェクトをdebuged。それは完全です。つまり、すべてのリストが存在します。だから私はエラーが私の見解と関係があると思う - 私はどのようにオブジェクトを呼び出す。

答えて

0

私は自分で解決策を見つけました。私はリストのオブジェクトが私のフォーム

<form class="form-horizontal" th:modelAttribute="anonymization" th:object="${anonymization}" th:action="@{'monitoringsystem/' + ${mId} + '/anonymisatzion/save'}" method="post"> 
     <input type="hidden" th:field="*{id}"/> 
     <fieldset> 
      <legend>Set Anonymization</legend> 
      <div class="panel panel-default"> 
       <div class="panel-heading">Anonymizie Hostnames</div> 
       <div class="panel-body"> 
        <div class="form-group" th:each="host, statHost : *{hosts}"> 
         <label class="col-md-4 control-label" for="checkboxes" th:text="*{hosts[__${statHost.index}__].name}"></label> 
         <div class="col-md-4"> 
          <div class="checkbox"> 
           <label for="checkboxes-0"> 
            <input th:field="*{hosts[__${statHost.index}__].anonymizeName}" type="checkbox" /> 
            anonymizie 
           </label> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
      <div class="panel panel-default"> 
       <div class="panel-heading">Anonymizie Items</div> 
       <div class="panel-body"> 
        <div class="form-group" th:each="item, statItem : *{items}"> 
         <label class="col-md-4 control-label" for="checkboxes" th:text="*{items[__${statItem.index}__].name}"></label> 
         <div class="col-md-4"> 
          <div class="checkbox"> 
           <label for="checkboxes-0"> 
            <input th:field="*{items[__${statItem.index}__].anonymizeName}" type="checkbox" /> 
            anonymizie name 
           </label> 
          </div> 
          <div class="checkbox"> 
           <label for="checkboxes-0"> 
            <input th:field="*{items[__${statItem.index}__].anonymizeData}" type="checkbox" /> 
            anonymizie data 
           </label> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
      <div class="panel panel-default"> 
       <div class="panel-body"> 
        <div class="form-group"> 
         <label class="col-md-4 control-label" for="singlebutton"></label> 
         <div class="col-md-4"> 
          <a th:href="@{/monitoringsystem}" class="btn btn-default btn-small">Cancel</a> <button id="singlebutton" name="singlebutton" class="btn btn-primary btn-small">Submit</button> 
         </div> 
        </div> 
       </div> 
      </div> 
     </fieldset> 
    </form> 

Futhermoreに呼ばれている方法を変更し、すべての拳ゲッターとセッターの命名に問題があるように思われます。

setBoolean(boolean b){ 
    this.b = b; 
} 

isBoolean(){ 
    return b; 
} 

春またはthymeleaf(私が担当するコンポーネントを知らない)getで始まるゲッターを必要とするようだ:鉱山は、のようなものでした。これを変更した後、今すぐ動作しています。

setBoolean(boolean b){ 
    this.b = b; 
} 

getBoolean(){ 
    return b; 
}