Accessing an Object's Method inside a JSP

T

TheVooDooChild

I have a JSP with a hidden field:
<html:hidden name="FrmCustomerHolding" property="localTag" />

localTag is of type Tag in my form (private Tag localTag;) and has
methods "getTagName()" & "getTagValue()", both return a String.

In my JSP I need to access the methods of this object and I'm getting
the error "Object doesn't support this property or method". I'm trying
to access these methods in a javascript function and the code is:

newFile.WriteLine("Local Tag: " +
document.getElementById("localTag").getTagName().value +
document.getElementById("localTag").getTagValue().value);


Can someone please help with this?
Thanks!
 
A

Andrew Thompson

I have a JSP with a hidden field:
<html:hidden name="FrmCustomerHolding" property="localTag" />

localTag is of type Tag in my form (private Tag localTag;) and has
methods "getTagName()" & "getTagValue()", both return a String.

In my JSP I need to access the methods of this object and I'm getting
the error "Object doesn't support this property or method". I'm trying
to access these methods in a javascript ..

Whoa up!

The JS is calculated on the client side. By that time,
your object has vanished (or rather, it never left the
server) and the user has a mix of HTML and JS. It is not
possible to access the server-side object from a client-side
script.

The best you can do is write the attributes of the object
as HTML (while still at the server), then use JS on the
client-side to access or manipulate that HTML.
 
T

TheVooDooChild

So, can I create two hidden fields that actually contain the Strings
returned from the object's method? Something like:

<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagName()" %>' />
<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagValue()" %>' />

If I can do something like this, what is the correct syntax and how do
I access this property in my javascript?
 
O

Oliver Wong

TheVooDooChild said:
So, can I create two hidden fields that actually contain the Strings
returned from the object's method? Something like:

<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagName()" %>' />
<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagValue()" %>' />

If I can do something like this, what is the correct syntax and how do
I access this property in my javascript?

You're on the right track. At this point, however, you'd probably be
better off asking an JavaScript newsgroup rather than a Java one.

- Oliver
 
R

Roedy Green

The JS is calculated on the client side. By that time,
your object has vanished (or rather, it never left the
server) and the user has a mix of HTML and JS. It is not
possible to access the server-side object from a client-side

If you want to bring out the big guns you can. You need RMI on both
Server and Applet client. A watered down version is to ship a
serialized object, either over a socket or as if you were downloading
a file with http.

There are probably other lighter ways to skin your cat.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top