There is no direct conversion between Java and Javascript objects (I hear tell 
of some libraries to do this though...)

What you'll need to do otherwise is iterate over the List and construct 
Javascript from it, something like this:

<html><head><title>test</title><script>
myArray = new Array();
<%
  int i = 0;
  for (Iterator it = myForm.getTheList().iterator(); it.hasNext(); ) {
%>
    myArray[<%=i%>] = "<%=it.next()%>";
%>
    i++;
  }
%>
</script><head><body>
You now have an array named myArray in Javascript, populated with the data from 
the list
</body></html>

You can of course do this with taglibs, and in some ways it's better, but the 
underlying theory is the same either way.  You'll wind up with something like 
this rendered to the browser:

<html><head><title>test</title><script>
myArray = new Array();
    myArray[0] = "value1";
    myArray[1] = "value2";
    myArray[2] = "value3";
</script><head><body>
You now have an array named myArray in Javascript, populated with the data from 
the list
</body></html>

That's it.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Mon, December 20, 2004 10:58 am, Zhang, Larry \(L.\) said:
> Say I have an action form
> 
> MyForm extends ActionForm {
>  List employeeList;
>  //set/getter follows...
> }
> 
> Suppose in my action class's execute method,
> I populated employeeList from database, and do
> myForm.setEmployeeList(List someData);
> 
> Now in my Jsp, how to get this value and assign this value to a java
> script variable?
> 
> Such as:
> 
> In my jsp:
> 
> <% List iWantToGetThisList = ??? %>
> 
> I know one way is that in the action's execute method, I put the
> employeeList in the request using request.setAttribute("employeeList",
> employeeList); but I don't want to do this way...
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to