Hi Alvin,

Alvin Townsend wrote:
java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
net.sf.click.util.ContainerUtils.ensureObjectPathNotNull(ContainerUtils.java:592)
        at 
net.sf.click.util.ContainerUtils.copyContainerToObject(ContainerUtils.java:318)
        at 
net.sf.click.util.ContainerUtils.copyContainerToObject(ContainerUtils.java:355)
        at net.sf.click.control.Form.copyTo(Form.java:1710)

This normally happens when an object is instantiated which does not have a default empty constructor. When you specify a path for your field e.g. new TextField("address.price"), Form.copyTo will navigate the
object graph according to the path. Say you have the following:

 field = new TextField("address.price")
 ...
 form.copyTo(client);

the copy logic will try and navigate to the Address from Client. But if Address is null on Client Click attempts to create a new Address. But the only way this works is if Address has a default no arg constructor:

public class Address {
 public Address() {}
}

If your Address cannot have a no-arg constructor the best way to resolve this is to ensure your domain objects are valid before invoking form.copyTo(). You could do this by overriding Form.copyTo:

public void onInit() {
   ...
   form.copyTo(client) {
       if (client.getAddress() == null) {
           client.setAddress(createAddress());
       }
       super.copyTo(client);
   };
}

Does this help?

kind regards

bob

Reply via email to