I'm clearer now on what you're looking to do. If

that[0].Cheetah.name
that[1].Monkey.name

works, then ModelDriven should work just fine.

Having said that, the following code snippet should work for you (haven't tested it though). This is slightly different than what you asked for in that what you end up with in animals is a list of AnimalHolders rather than animals.

    class MyAction implements ModelDriven {
        private List animals = new OgnlList(AnimalHolder.class);
        public Object getModel() { return this.animals ; }
        ...
    }

    class AnimalHolder {
        private AbstractAnimal animal;
        public AbstractAnimal getMonkey() throws Exception {
            return this.getAnimal(Monkey.class);
        }
        public AbstractAnimal getCheetah() throws Exception {
            return this.getAnimal(Cheetah.class);
        }
        public AbstractAnimal getAnimal(Class clazz) throws Exception {
            if( this.animal == null ) {
                this.animal = clazz.newInstance();
            }
            return this.animal;
        }
    }

    class OgnlList extends ArrayList {
        private Class clazz;

        public OgnlList(Class clazz) {
            this.clazz = clazz;
        }

        public synchronized Object get(int index) {
            while (index >= this.size()) {
                try {
                    this.add(clazz.newInstance());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return super.get(index);
        }
    }

M




------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to