• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

POSTing data from an applet

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make each web page in applet.
So for the first page, I have written a LoginApplet.
What I want this to do is, when the user enters the login and password and clicks the submit button,
the applet should force the browser to send a POST request to the Web Server.

How can I do this?
I know that I can invoke Javascript from JavaFX using AppletStageExtension.eval(someJavaScriptFunc())

And I found the following code:
http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/

but this Javascript code require parameters.

What I really want to know is how to send parameters to this function.... or alternatively, how I can send a POST from a JavaFX applet . . .

Javascript is an amazing language, but I am a newbie there . . . so any help will be appreciated . . .
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to make each web page in applet.


This seems an odd way of using applets, JavaFX ones or otherwise.

If an applet needs to display several pages/windows, then there are layouts that can do this (CardLayout). That would be much faster than having to initialize an applet on each page.

What benefit would you get from having multiple applets, especially if the applets do things as basic as handling logins (which is something that HTML forms can do just as well) ?
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of implementing it that way.

I have not written a lot of web based front ends, so the logical flow for me was to to have the applet forward the request to the next page just like it is done in html.

One advantage that I thought of was that I can test all the different parts independently rather than testing one application.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Putting applets on each page is a usability killer. You should keep their number to an absolute minimum.

Why do you want to use applets to begin with? What do they provide for your application that HTML/CSS/JavaScript can't?
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using applets because
1) I am Java programmer and quite comfortable programming in Java.
2) I was asked to prototype a web based UI even though I had never done anything more than build simple HTML pages and simple applets.
My investigation into various tools and technologies told me that the in-thing nowadays was RIA and that there were plenty of ways to do this:
a) JavaFX
b) Flex
c) Silverlight
d) Javascript libraries, jQuery, Dojo, and lots of others.

Given that I was a Java programmer, I opted to try out option a) :-)
So I self taught JavaFX and started developing the front end.

Hey, don't put down applets . . . JavaFX Applets 1.2 are way cooler (and faster) than Java Applets 1.0.2

But alas, this is only a prototype. I might need to move to Silverlight and the Evil Empire sooner than later :-)
Actually, my recent investigations into the Dark Side of the Force, tells me that the Dark Side is (presently) better than the Good side. LINQ, Attributes and Delegates makes up the two sided red light saber.

Anyway, I have a workaround to the question posted in this topic:

Access the JavaFX variables from Javascript like so:




That way, it is not needed to pass any variables while using the AppletStageExtension since Javascript can simply access the data while executing the doPost() function.

To pass parameters, I did the following: (but I am sticking with the above approach in my implementation)



Eeeww! Netscape reminds me of the Java 1.0.2 Applets, so I think that I will stay away from code like that . . .
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not arguing against applets, I'm arguing against using applets like web pages. Applet GUIs have way more capabilities than HTML GUIs, and one should use them accordingly (and not through a page-oriented approach).

A more modern way to access the surrounding web page than to use LiveConnect would be the Common DOM API.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mathew Kuruvilla wrote:the logical flow for me was to to have the applet forward the request to the next page just like it is done in html.


Urm, in Web 1.0 HTML... :-D
Today, even in pure HTML (with a good sprinkle of JavaScript, of course), the trend is to remain on the same page for most operations: JavaScript is in change of communicating with the server via HTTP XML (or Json or other) requests, receiving the answer and dynamically updating the page with the results.
That's called Ajax... ;-) (your option d)

In JavaFX (or regular applets), you can do exactly the same thing. You don't even have to reach down the JavaScript level, JavaFX has a full blown HttpRequest API with Json and XML parsers to use the answer. You can find several samples from official JavaFX site which query a server (like Yahoo! or Flikr) and update the applet.

In JavaFX, you can just switch scenes when you need to change dramatically the content (from login screen to main display, for example).
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ulf, Philippe
It didn't occur to me to have TWO scenes in one app. It makes more sense to do that than have the GUI as applets in different pages. On the other hand, my login.jar is 55KB, and my app.jar is 57KB. Let us say that the final app is 250KB.
In this case, will there be any noticeable difference in loading up the GUI in the two cases where the app is split into 80KB chunks as opposed to one 250KB chunk?

The reason why I did not go the Ajax route using Dojo was because the initial idea was to deliver the prototype in 3 weeks . . . When this got delayed (indefinitely?) I did read up on Ajax a bit and was trying to learn Dojo, but I never gained sufficient confidence that I could port whatever I had done in JavaFX to Dojo.

Anyway, at this point, porting if any, will be in Silverlight than Dojo.

I am not using JavaFX HttpRequest in my app as it does not support SSL. I am using HttpsURLConnection from Java instead, but I am using the PullParser from JavaFX.
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic