Possible to retrieve properties/values from Java object?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Possible to retrieve properties/values from Java object?

Post by Jenk »

.. into a form, in 'realtime'?

Someone has asked me to look into the possibility of using a Java applet as a CAPTCHA, but to avoid submitting a form and/or new page request, so ideally they would like a generated value from the applet to be available 'realtime' for submission with the rest of the form, or is submitted as the resulting value..

Is this possible?

So the html would look something along the lines of:

Code: Select all

<html>
<body>
<script type="text/javascript">
function doStuff()
{
    var data = document.getElementById('applet').myAppletPropertyOrValue;
    //do something with data..
}
</script>
<form action="page.php" method="post" onSubmit="doStuff(); return false;">
<object name="MyJavaApplet" id="applet" code="MyApplet" />
<input type="submit" />
</form>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

You can do it with javascript I'm pretty sure... let me look in my book and see if I can find anything for ya... hang on

Well, it says a few things about scripting with java, but it's a little over my head at the moment. It is possible (as far as i can tell) and it explains it as if you can just access the properties directly, but I think it must be a little more complicated than that.

Sorry i couldn't help ya.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Yes, it can be done. The project I am working on now (in PHP) is being revamped from a Java project that did use this. How it did, I know not. But I know it can be done.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Thanks guys, will keep burrowing. (could take a while.. "Java Object" tends to return just a few results :P)

So far I've ascertained you can force a submit with the applet, so that is a possible route.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

yes it can be done.

I have done something like this in the past:

Code: Select all

<script>
document.appletName.methodName(arg);
</script>

<applet code="someApplet.class" codebase="classes/" id="appletName" name="appletName">
obviously the methods need to be public
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

excellent, thank you!
Post Reply