views:

40

answers:

1

I have the following bean method signatures:

public String foo();  
public List<String> getList(String bar);  
public String getName(String baz);  

The following works for me:

$("#div_id").append('<%= beanId.foo() %>');

The following is what I would like to do, but is a little more complex though, and I can't get it to work.

var list = '<%= beanId.getList("bar") %>';  
for ( var i in list ) {  
  $("#div_id").append('<%= beanId.getName('list[i]') %>');
}

What is the correct way of doing this?

+1  A: 
$("#div_id").append('<%= beanId.foo() %>');

works because the jsp-stuff is parsed on the server while creating the website, so you have the resulting code in you string.

$("#div_id").append('<%= beanId.getName('list[i]') %>');

this can't work because your javascript-variable is just known on the client-side after the sever has created the page. do what you want on server-side or use ajax instead.

oezi
Yes, I basically have to interact using get requests then. I've since changed the code accordingly. Thanks.
Curtor