2011-03-03 57 views
3

我试图将一个复选框绑定到我的POJO上的项目列表。弹簧绑定/速度到支持列表

class SimplePOJO { 
    private List <Key> selectedEntities = new ArrayList<Key>(); 
    public void setSelectedEntities(List <Key> a) { this.selectedEntities = a; } 
    public List <Key> getSelectedEntities() { return this.selectedEntities; } 
} 

速度标记:

#springBind("command") 
#springFormCheckBox("command.selectedEntities", "") 

这并不在所有的工作,只是输出代码一字不差。

尝试使用标准项目:

<input type="checkbox" 
    #if ($command.selectedEntities.contains($item)) checked="checked" #end 
    value="$item.key" /> 

每当我检查所有的箱子并提交表单,我支持bean列表保持为空。我怎样才能将设置值完成到列表中?

注:我也尝试在POJO如下:

private List <Key> selectedEntities = new AutoPopulatingList <Key>(Key.class); 

环境:春天3.0.5,极速引擎1.7

回答

1

我需要绑定代码:

#springFormCheckbox("command.selectedEntities[$velocityCount]", "id=entity$velocityCount value=$item.key #if($command.selectedEntities.contains($item.key)) checked=checked #end ") 

我倾向于在现场版有一个错字,而不是这个简单的例子。

0

也许你需要这样的:

#springFormCheckboxes("command.selectedEntities" $labels " " "") 

其中$labels是从Key到其复选框标签的映射,第三个参数是复选框之间的分隔符,第四个参数是任意属性。

参见:

+0

我可能没有正确解释这一点,但我有一个对象显示给用户的列表。我有一个我想要显示给用户的复选框(每行) - 我需要知道他们检查了哪些行,以便当他们提交表单时,我可以采取适当的行动。问题是我无法让他们进入项目列表。 – Scott 2011-03-05 22:54:52