You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Van Wart <sc...@indosoft.com> on 2008/04/21 21:21:41 UTC

Indexed nested beans

Hi all,

I'm trying to get multiple levels of indexed, nested beans working.  
I've tried a variety of solutions but I keep getting xwork or ognl 
exceptions.  Here's what I've tried (loosely):

    public class MyAction implements Action, StrutsStatics {
      private List<PackageBean> packages;
      public List<PackageBean> getPackages() { return this.packages; }
      public List<PackageBean> setPackages( List<PackageBean> packages ) 
{ this.packages = packages; }
    }

    public class PackageBean {
      private List<ElementBean> elements;
      public List<ElementBean> getElements() { return this.packages; }
      public List<ElementBean> setElements( List<ElementBean> packages ) 
{ this.elements = elements; }
    }

    public class ElementBean {
      private String property1;
      private String property2;
      // getters and setters
    }

I refer to the properties in my inputs as 
"packages[0].elements[0].property1".  When I POST, I get a 
NullPointerException in OgnlRuntime.getField (targetClass is null).

I tried using built-in arrays (PackageBean[] and ElementBean[]) and I 
get an OgnlException (source is null in setProperty( null, "property1" 
)).  I try initializing these to new PackageBean[0] and new 
ElementBean[0] and I get IndexOutOfBoundsException.

I tried pre-populating my collections (List<...>) with a few empty beans 
in both my action and PackageBean but I get the "source is null" 
exception again... I also tried the getPackage( int index ) and 
setPackage( int index, PackageBean pkg ) style getters and setters all 
the way through (initializing the lists with empty beans as necessary) 
with no success.

Am I way off on my thoughts of how nested beans and indexed properties work?

Thanks,
  Scott


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


(SOLVED) Indexed nested beans

Posted by Scott Van Wart <sc...@indosoft.com>.
I was missing the getPackages() method :(

- Scott

Scott Van Wart wrote:
> Hi all,
>
> I'm trying to get multiple levels of indexed, nested beans working.  
> I've tried a variety of solutions but I keep getting xwork or ognl 
> exceptions.  Here's what I've tried (loosely):
>
>    public class MyAction implements Action, StrutsStatics {
>      private List<PackageBean> packages;
>      public List<PackageBean> getPackages() { return this.packages; }
>      public List<PackageBean> setPackages( List<PackageBean> packages 
> ) { this.packages = packages; }
>    }
>
>    public class PackageBean {
>      private List<ElementBean> elements;
>      public List<ElementBean> getElements() { return this.packages; }
>      public List<ElementBean> setElements( List<ElementBean> packages 
> ) { this.elements = elements; }
>    }
>
>    public class ElementBean {
>      private String property1;
>      private String property2;
>      // getters and setters
>    }
>
> I refer to the properties in my inputs as 
> "packages[0].elements[0].property1".  When I POST, I get a 
> NullPointerException in OgnlRuntime.getField (targetClass is null).
>
> I tried using built-in arrays (PackageBean[] and ElementBean[]) and I 
> get an OgnlException (source is null in setProperty( null, "property1" 
> )).  I try initializing these to new PackageBean[0] and new 
> ElementBean[0] and I get IndexOutOfBoundsException.
>
> I tried pre-populating my collections (List<...>) with a few empty 
> beans in both my action and PackageBean but I get the "source is null" 
> exception again... I also tried the getPackage( int index ) and 
> setPackage( int index, PackageBean pkg ) style getters and setters all 
> the way through (initializing the lists with empty beans as necessary) 
> with no success.
>
> Am I way off on my thoughts of how nested beans and indexed properties 
> work?
>
> Thanks,
>  Scott
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


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