views:

55

answers:

4

Hi everyone! I am working on a project which is basically a Java application with an embedded IE browser (using JDIC 0.9.5) to display custom HTML files (stored locally that I created). I have a test HTML file with a JavaScript function that checks a simple form with checkboxes and alerts the user with a dialog stating which checkboxes are checked.

My question is, is there a way for my Java application to do the same procedure on the embedded HTML form instead of using JavaScript. I want to keep my application and HTML files simple without the clutter of JavaScript in my HTMLs or a pile of .js files. Thanks for any help and guidance!

A: 

You could replace your model with a client-server model using Java Server Pages (JSP).

mcandre
Thanks mcandre, JSP looks like where I will be heading to further this project
A.Donahue
A: 

If you are displaying the page through an embedded browser it is very unlikely that you will be able to get access to the DOM via Java.

One option is to use GWT javascript compiler to code in java and then convert to javascript. If it will only use IE, then you will only need to keep one of the generated .js files, so the clutter will be low.

bashflyng
Thanks bashflyng, I'd figured it was gonna be a difficult task, so it never hurts to ask lol
A.Donahue
A: 

Since you're embedding your HTML files in your own Java program, I would recommend you to use one of these 2 approaches:

1.- Use Javascript and structure the files cleanly, is not that complex.

2.- When you do the POST check the values in your Java code and return a new dynamically generated HTML file with needed info

I sincerely recommend you to follow the first option. Other options to work with Java in HTML would be JSP or GWT, but both will require a proper J2EE server, which would be overkill in your application

Carlos Tasada
Thanks Carlos for the info
A.Donahue
+1  A: 

You have two options. Either shift the project to run the Java on the server side using JSP technology inside a web container like Apache Tomcat or Jetty, or write you web page to open up a Java applet.

The applet route allows you to run the code on someone else's machine, and as a trade off you will have to run the application in a strongly security constrained environment. After all, if someone were to run code on your machine, you wouldn't want it able to access your disk, etc.

The JSP solution will have you running the code on the same machine as your web server, since you (probably) control your own web server, the code will not be ran with as many security constraints enabled. This means the code can make requests to other machines, write and read files, etc.

Edwin Buck
Cool thanks Edwin, I am not too far along with project, so I'll have to spec out JSP and see if it fits my project needs, I appreciate your feedback :)
A.Donahue