click-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alvin Townsend" <alvin.towns...@gmail.com>
Subject Re: "Wrong Number of Arguments" Error in Form.copyTo()
Date Sun, 19 Oct 2008 19:30:22 GMT
Hi Bob,

That makes a lot of sense. Many of our objects cannot be instantiated
without arguments to the Constructors, so I've made sure that all of
them were set up previously and that the Form.copyTo wouldn't come
across anything null.

Form.copyTo() should only be coming across simple single-argument
setters. The object graph (past the Constructors) is very
straightforward. For the life of me I cannot see what's choking
Form.copyTo()...

If I come up with something brilliant, I'll let you know. :-)

Thanks again!

Alvin

On Sun, Oct 19, 2008 at 2:58 PM, Bob Schellink <sabob1@gmail.com> wrote:
> 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
>
>

Mime
View raw message