You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by don <do...@cameronsoftware.com> on 2003/10/17 19:03:27 UTC

Veclocity and Object properties in ArrayList

I am having problems getting properties from objects which are put into an
ArrayList.  Here is the code which creates the ArrayList:

 

 

ArrayList lImages = new ArrayList();

 

for (int i=0; i<6; i++) {

ImageRef lImage = new ImageRef("Test"+i+".jpg", "This is a test "+i);

            lImages.add(lImage);

}

lContext.put("images", lImages);

 

 

This is the class for the ImageRef:

 

            private class ImageRef {

 

                        private String _FileName;

                        private String _Caption;

 

                        private ImageRef() {}

 

                        public ImageRef(String aFileName, String aCaption) {

                                    _FileName = aFileName;

                                    _Caption = aCaption;

                        }

 

                        public String getFileName() {

                                    return _FileName;

                        }

 

                        public String getCaption() {

                                    return _Caption;

                        }

            }

 

 

This is the velocity template:

 

#foreach ($image in $images)

            $image.caption

$image.Caption

$image.getCaption()     

            #end

        

Which produces the result:

 

 

            $image.caption

            $image.Caption

            $image.getCaption()     

            $image.caption

            $image.Caption

            $image.getCaption()     

            $image.caption

            $image.Caption

            $image.getCaption()     

            $image.caption

            $image.Caption

            $image.getCaption()     

            $image.caption

            $image.Caption

            $image.getCaption()     

            $image.caption

            $image.Caption

            $image.getCaption()     

 

I have gone through the manual, but with no luck. Any ideas?

 

Thanks

Don

 

 

 

 

 

Don Cameron

Director - Sr. Software Architect

Cameron Software Ltd.

 

(250) 889-2480

don@cameronsoftware.com

 


Re: Veclocity and Object properties in ArrayList

Posted by Nathan Bubna <na...@esha.com>.
Dave Newton said:
> On Fri, 2003-10-17 at 13:03, don wrote:
> >             private class ImageRef {
>
> It's private--Velocity can only access public stuff (is that right?)

yep. :)

if i've said it once, i've said it at least... hmm... four times! (give or
take a dozen ;)

Nathan Bubna
nathan@esha.com


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


Re: Veclocity and Object properties in ArrayList

Posted by Dave Newton <da...@solaraccess.com>.
On Fri, 2003-10-17 at 13:03, don wrote:
>             private class ImageRef {

It's private--Velocity can only access public stuff (is that right?)

Dave



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


Re: Veclocity and Object properties in ArrayList

Posted by Brian Lloyd-Newberry <ne...@yahoo.com>.
Don,

What do you get if you put a $image in that #for loop? I would suspect 
that the private class is giving you problems with introspection. If 
that is the case, could make the class implement a public interface?

-Brian


don wrote:
> I am having problems getting properties from objects which are put into an
> ArrayList.  Here is the code which creates the ArrayList:
> 
<snip />
> 
> This is the velocity template:
> 
> #foreach ($image in $images)
> 
>             $image.caption
> 
> $image.Caption
> 
> $image.getCaption()     
> 
>             #end
> 
> Which produces the result:
> 
>             $image.caption
> 
>             $image.Caption
> 
>             $image.getCaption()     
> 

>             $image.caption
> 
>             $image.Caption
> 
>             $image.getCaption()     
<repeat times="5"/>

> I have gone through the manual, but with no luck. Any ideas?



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