Copy the Form's field values into the given object's attributes. In other words automatically populate Object attributes with the Form's field values.
The following example populates the Customer attributes with the Form's field values:
public void onPost() { if (form.isValid()) { Customer customer = new Customer(); form.copyTo(customer); .. } return true; }
copyTo also supports
java.util.Map as an argument.
By specifying a map, the map's key/value pairs are populated from matching Form field names. A match occurs when a field's name is equal to a map's key.
The following example populates the map with the Form field values:
public void onInit() { form = new Form("form"); form.add(new TextField("name")); form.add(new TextField("address.street")); } public void onGet() { Map map = new HashMap(); map.put("name", null); map.put("address.street", null); form.copyTo(map); }
Note that the map acts as a template to specify which fields to populate from. For more information on how Fields and Objects are copied see {@link org.apache.click.util.ContainerUtils#copyContainerToObject(org.apache.click.control.Container,java.lang.Object)}.
@param object the object to populate with field values
@throws IllegalArgumentException if the object parameter is null