Spring Binding / Speed ​​to Support List

I am trying to bind a checkbox to a list of items in my 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; }
}

Speed ​​Marking:

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

This does not work at all, it simply outputs the code verbatim.

Trying to use standard elements:

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

Whenever I check any of the fields and submit the form, my backup bean list remains empty. How to configure the values ​​in the list?

Note. I also tried doing the following in POJO:

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

Environment: Spring 3.0.5, Velocity Engine 1.7

+3
source share
2 answers

Required Binding Code:

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

I tend to have a typo in the live version instead of this simplified example.

+1
source

Perhaps you need this:

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

$labels - Key ., - , - .

. :

0

Source: https://habr.com/ru/post/1796147/


All Articles