2017-04-12 89 views
0

我有一个包装类,像这样:索引进式“com.ItemBean”不支持

@NoArgsConstructor 
@Data 
public class ListWrapper { 

    public ListWrapper(List<Object> objects) { 

     this.objects = objects; 
    } 

    private List<Object> objects; 

} 

我期待来填充自定义bean的包装。我们称它为一个ItemBean。

于是我有:

@GetMapping("/rentSetup") 
public String setupRent(@RequestParam("companyId") Integer companyId, 
         Model model) { 

    List<Object> beans = new ArrayList<>(); 
    ItemBean bean = new Builder() 
       .someProperty(something) 
       .build(); 
    beans.add(bean); 

    ListWrapper wrapper = new ListWrapper(beans); 
    model.addAttribute("itemBeansWrapper", wrapper); 
    return "setup"; 
} 

我想有用户编辑属性someProperty在视图。我在想,我会做:

<form th:object="${itemBeansWrapper}" 
     th:action="@{/setup(companyId=${companyId})}" 
     th:method="post"> 

    <div th:each="bean, iterStat : ${itemBeansWrapper.objects}"> 
     <input type="number" 
      th:name="${bean[__${iterStat.index}__].someProperty}"> 
    </div> 

    <button type="submit" 
      th:name="action" 
      th:value="review" value="review"> Review 
    </button> 
</form> 

但是这会导致:

org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 4): Indexing into type 'com.ItemBean' is not supported 
    at org.springframework.expression.spel.ast.Indexer.getValueRef(Indexer.java:176) 

我在做什么错?

请注意,我也有我的控制器与@SessionAttributes({"companyId", "itemBeansWrapper"})注释,因为我想坚持跨页包装了会议。

如果我离开了[__${iterStat.index}__],页面编译得很好,但我想我需要类似的东西来区分嵌套的bean。

回答

0

抓住了我的错误。它应该是:

<input type="number" th:field="*{objects[__${iterStat.index}__].someProperty}"/>