You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <st...@reumann.net> on 2005/04/05 20:00:17 UTC

questions concerning Lists and indexes and lazy lists, oh my

Ok, I thought I had a pretty firm grasp on the use of Lists for form 
bean properties and everything works fine in my applications that use 
Lists for properties. (If I need to make sure the List can grow I wrap 
them in a LazyList in the reset method like..

//reset(..)
myList = ListUtils.lazyList(new java.util.ArrayList(),
         new Factory() {
             public Object create() {
                 return new ObjectTypeInMyList();
             }
         });


The question I have is in regard to this wiki about Indexed properties 
and LazyLists...

http://wiki.apache.org/struts/StrutsCatalogLazyList

For my Lists in my ActionForms I provide no getMyList(int index) method, 
yet everything works fine.

What I'm confused about is the section in the above link titled:

"Hand Cranking lazy List in the ActionForm"

For those not wanting to look at the link it shows an ActionForm like:

----------------------------------------------------
public class SkillActionForm extends ActionForm {

       protected List skills = new ArrayList();

       public List getSkills() {
           return skills;
       }

       // non-bean version so as not to confuse struts.
       public void populateSkills(List skills) {
           this.skills.addAll(skills);
        }

       public void setSkills(SkillBean skill) {
           this.skills.add(skill);
       }

       public SkillBean getSkills(int index) {

           // automatically grow List size
           while (index >= skills.size()) {
               skills.add(new SkillBean());
           }

           return (SkillBean)skills.get(index);

       }
   }
----------------------------------------------------

My question is how does Struts/BeanUtils handle two get methods that 
have different signatures but the same method name, and what exactly is 
going on?

public List getSkills()
public SkillBean getSkills(int index)

For example, in my code, I do not provide a getSkills(int index) type of 
method yet form fields that look like...

<input type="text" name="skills[4].someSkill" value=".."/>

Will work just fine.

So what happens behind the scenes when I do not provide the 
getSkills(int index) method and how is it working with/or without it?

Confused,
-- 
Rick

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


Re: questions concerning Lists and indexes and lazy lists, oh my

Posted by Rick Reumann <st...@reumann.net>.
Wendy Smoak wrote the following on 4/5/2005 3:50 PM:

> In light of that, I would bet the BeanUtils code always uses the
> getWhatever() method, and then gets/sets the requested index directly on the
> List or array.  Seems logical to me, but I have not run it in a debugger or
> looked at the code to be certain.

Thanks Wendy. That makes sense. Sorry for being lazy and not reading the 
spec:)

-- 
Rick

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


Re: questions concerning Lists and indexes and lazy lists, oh my

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Rick Reumann" <st...@reumann.net>
>
> My question is how does Struts/BeanUtils handle two get methods that
> have different signatures but the same method name, and what exactly is
> going on?
>

See section 7.2 of the JavaBeans Specification for info on indexed
properties.  The indexed get/set methods are optional.  "A component MAY
also expose an indexed property as a single array value." (emphasis mine).
(They also must be arrays-- BeanUtils extends the spec to allow Lists.)

In light of that, I would bet the BeanUtils code always uses the
getWhatever() method, and then gets/sets the requested index directly on the
List or array.  Seems logical to me, but I have not run it in a debugger or
looked at the code to be certain.

-- 
Wendy Smoak


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