• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

please help me to pass form bean values to the script function

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i pass the values from body to script fucntion while loading.i,e using onload attribute. I have tried all the ways which I know but there javascript errors like undefined, null.... .I have tried to write my code here.But there are errors while loading the post.Thats why I am unable to write the code.
Please help me to resolve the issue.
Thanks in advance
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to diagnose your problem without seeing your code and knowing what specific errors you're getting. Please try again to post your code.

Here is a bit of information about posting JavaScript code on JavaRanch

For the sake of safety, Javaranch "filters" certain JavaScript constructs in a post. For example, you can't post the word "onclick" inside a pair of <> brackets. The same is true of other words such as onload. To get around this restriction, just misspell the words (onklick, onlode, etc.) and we'll know what you mean.
 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All.,

I need to pass the form bean (struts) String array values to the script function.I have tried all the ways which I know.But I didnt get the solution.Here I am showing the scenario in short.

MyForm.java
-------------

private String records[]; and their getters and setters.

MyJsp.jsp
------------
<script>
function toDoList(records)
{
..........
return true;
}
</script>
<body onloadfunction="return toDoList(records)">
<html:form>
<html:hidden property="records">
</html:form>
</body>
for this one I am getting java script error---- records undefined.
and also
<body onloadfunction="return toDoList(<%= session.getAttirbute("records")%> ">
for this one I am getting java script error---- ] expected at <body>
but the values are setting in to the bean in both ways
and in another one I am getting null like that.
Please help me to solve the problem.
Thanks in advance.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's important to understand that the only way you can pass Java values that exist on the server to JavaScript values that exist on the browser is by having your JSP become a sort of JavaScript code generator that will produce the JavaScript code that you need.

In your particular case, you want to take an array of values that exists on the server and use it to create a JavaScript array. I'd suggest you not try to pass it as a parameter, but just use it to create the JavaScript array. Here's an example


This way the javascript array "records" gets regenerated every time the page is refreshed from the server-side Java array "records". Note that the above assumes your web application is Servlet version 2.4. If not, you will have to enclose ${record} with a c:out tag. Also, the above code assumes that each element of records is a String. If it's a complex data type, you will have to further break down each element into string components and create a corresponding JavaScript object with the same properties.
[ December 10, 2007: Message edited by: Merrill Higginson ]
 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Merill. Thank you very much.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic