You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jakub Bogusławski <j....@post.pl> on 2002/11/07 14:19:53 UTC

Problem with passing object array into Velocity context

Hello

I have problem with passing array of objects into Velocity context, or
rather with accessing fields of these objects. Here is some of my
code:

Java Servlet

class Category {
 String parent="", name="";
 int id=0;
			
 public Category(int idp, String parentp, String namep) {
  id=idp;
  name=namep;
  parent=parentp;
 }

}

Category[] categories = new Category[4];
categories[0]=new Category(10001,"Top","Ankieta");
categories[1]=new Category(10002,"Top","Badania");
categories[2]=new Category(10003,"Top","Rezultaty");
categories[3]=new Category(10004,"Top","Wydruki");
			
ctx.put("categoriesList",categories);

and Velocity template

<select name="tCategory">
#foreach( $category in $categoriesList )
	 <option VALUE="$category.id"> $category.parent >> $category.name
</OPTION>
#end
</select>

And now html output!!!

<select name="tCategory">
	 <option VALUE="$category.id"> $category.parent >> $category.name
</OPTION>
	 <option VALUE="$category.id"> $category.parent >> $category.name
</OPTION>
	 <option VALUE="$category.id"> $category.parent >> $category.name
</OPTION>
	 <option VALUE="$category.id"> $category.parent >> $category.name
</OPTION>
</SELECT>

Please help!! What am I doing wrong??

Kuba

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with passing object array into Velocity context

Posted by Jakub Bogusławski <j....@post.pl>.
Hello 

Thanks 'a lot Dennis . IT WORKS!!!

You are the greatest :).


Kuba



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with passing object array into Velocity context

Posted by Denis <ji...@respublica.fr>.
Your "Category" class doesn't have accessor methods. That won't work.

Add
   String getParent() { return parent; }
   String getName() { return name; }

and all should be fine....

-- Denis.

On Thursday, November 7, 2002, at 01:19  pm, Jakub Bogusławski 
wrote:

> Hello
>
> I have problem with passing array of objects into Velocity context, or
> rather with accessing fields of these objects. Here is some of my
> code:
>
> Java Servlet
>
> class Category {
>  String parent="", name="";
>  int id=0;
> 			
>  public Category(int idp, String parentp, String namep) {
>   id=idp;
>   name=namep;
>   parent=parentp;
>  }
>
> }
>
> Category[] categories = new Category[4];
> categories[0]=new Category(10001,"Top","Ankieta");
> categories[1]=new Category(10002,"Top","Badania");
> categories[2]=new Category(10003,"Top","Rezultaty");
> categories[3]=new Category(10004,"Top","Wydruki");
> 			
> ctx.put("categoriesList",categories);
>
> and Velocity template
>
> <select name="tCategory">
> #foreach( $category in $categoriesList )
> 	 <option VALUE="$category.id"> $category.parent >> $category.name
> </OPTION>
> #end
> </select>
>
> And now html output!!!
>
> <select name="tCategory">
> 	 <option VALUE="$category.id"> $category.parent >> $category.name
> </OPTION>
> 	 <option VALUE="$category.id"> $category.parent >> $category.name
> </OPTION>
> 	 <option VALUE="$category.id"> $category.parent >> $category.name
> </OPTION>
> 	 <option VALUE="$category.id"> $category.parent >> $category.name
> </OPTION>
> </SELECT>
>
> Please help!! What am I doing wrong??
>
> Kuba


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>