• 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

Javascript access to a Java object

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Java object on my JSP page
<% Object javaObject = myClass.getJavaObject(); %>

Can my JavaScript script access javaObject? How would it reference it?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dunno if will work with jsp, but there is a library called rhino, which has some bridging between java & javascript
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only way that JavaScript can access Java is either having Java Write the information to the page in some format that the JavaScript can decipher, post the page back to the server, or using Ajax ro communicate with the server.

Eric
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if I put the text in a sentence on the page like:

The status of the object is <%= javaObject.getStatus() %>.

Can I get a word out the the sentence if the sentence is not in a form? What if the sentence is in a table? If I can't get a 'word' out of the sentence, could I somehow get the whole sentence?

I'm trying to do a "confirm", but only in the case where the object has a certain state and not on every 'submit'.
[ June 12, 2005: Message edited by: Marilyn de Queiroz ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do it as simple as:


or as complicated as:



Eric
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Eric.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm stuck again.
I'm trying to do something like this:

onSubmit:

var inputFromForm = getInputFromForm();
var state = <%= javaObject.getStatus( inputFromForm ) %>
alert( "The status of the object is " + state )

Is it possible to use the input from the form in the jsp tag?

(I also seem to be having problems getting my input from the form, but if I can't even use the input, I'm not going to worry about that right now.)
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
var state = "<%= javaObject.getStatus( inputFromForm ) %>"
alert( "The status of the object is " + state )

think you may need the quotes around it....
If that does not work do a view source after the page has been rendered and see if what is being written to the page is what you wanted to appear. Are you getting an error? If so what does it say?

Eric
reply
    Bookmark Topic Watch Topic
  • New Topic