You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Néstor Boscán <ne...@tcs.com.ve> on 2007/09/15 03:38:09 UTC

BeanUtils setProperty IllegalArgumentException: Null property value for property

Hi
 
I suppose that this has been asked and answered before but I can't find the
solution. I have some classes like this:
 
public class Address {
  private City city;
 
  public City getCity () { return city; }
  
  public void setCity (City city) { this.city = city; }
}
 
public class City {
  private String name;
 
  public String getName ( return name; }
 
  public void setName (String name) { this.name = name; }
}
 
And I'm trying to set the city's name like this:
 
PropertyUtils.setProperty (address, "city.name", "Toronto");
 
And I'm getting IllegalArgumentException: Null property value for 'name'.
 
Now I checked the 1.6 BeanUtils code and it doesn't instantiate the class
anywhere. Is this something that BeanUtils does?. If not does anybody knows
another technology that can do this?
 
Regards,
 
Néstor Boscán

Re: BeanUtils setProperty IllegalArgumentException: Null property value for property

Posted by James Carman <ja...@carmanconsulting.com>.
The City object must be instantiated already, I believe.  And, you
might want to try using setNestedProperty() rather than setProperty().

On 9/14/07, Néstor Boscán <ne...@tcs.com.ve> wrote:
> Hi
>
> I suppose that this has been asked and answered before but I can't find the
> solution. I have some classes like this:
>
> public class Address {
>   private City city;
>
>   public City getCity () { return city; }
>
>   public void setCity (City city) { this.city = city; }
> }
>
> public class City {
>   private String name;
>
>   public String getName ( return name; }
>
>   public void setName (String name) { this.name = name; }
> }
>
> And I'm trying to set the city's name like this:
>
> PropertyUtils.setProperty (address, "city.name", "Toronto");
>
> And I'm getting IllegalArgumentException: Null property value for 'name'.
>
> Now I checked the 1.6 BeanUtils code and it doesn't instantiate the class
> anywhere. Is this something that BeanUtils does?. If not does anybody knows
> another technology that can do this?
>
> Regards,
>
> Néstor Boscán
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org