views:

323

answers:

2

I'm really new to Java and I have to create an applet for signing documents electronically. The applet will be called from an ASP.Net web page application.

Right now, I embed the applet in page as a <object id="EDOCApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> and send parameters to the applet like this:

<PARAM id="EdocPath" NAME="EdocPath" value="\\some\where\file.txt" />

In the applet, I can get the value using applet's built-in method getParameter("EdocPath");

What I need is the ability to pass the applet a list of several files and their "display names". For instance, it would be simple to write it down like an XML string:

<DocumentList>
  <UnsignedDocument Path="\\some\wehere\file1.txt" Description="Whatever comes here" />
  <UnsignedDocument Path="\\some\wehere\file2.txt" Description="Something else" />
...

However, as far as I see in HTML4.01 specification, the PARAM HTML element may not have content and it has no end-tag.

The choices I'm considering, are:

  • html-encode the xml structure and send it to applet in a single PARAM object
  • creating a list of PARAM objects and constructing their names like "File1", "Description1", "File2", "Description2", "File3"... then in Java applet create a while loop to read filenames while there is any.

However, none of the solutions seems to be elegant. The question is, what's the best practice in this case?

+1  A: 

Pass them comma-separated:

<param id="files" name="files" 
     value="\\some\where\file.txt,\\some\where\file.txt" />

and then use String.split():

String[] fileNames = param.split(",");

In case of more complex structures you can use JSON to represent them.

Bozho
sounds reasonable in my scenario (I'll have to think about how to encode the descriptions, these may contain commas, too). But what would I do if I needed more complex structures to be sent to the applet, something like a tree?
naivists
you can use JSON :)
Bozho
Oh, yes, JSON! That should do the trick.
naivists
+1  A: 

You can also provide your applet with a public method:

initFile(String path, String description)

and call this method from javascript code (in which you can loop)

var applet = getElementByTageName(applet);
applet.initFile("yourPath","yourDescription");
Laurent K
This sounds good, too! How do I know, when to cal the JavaScript code, is there some "onload" event which is raised by the Applet? Or should the applet itself try to load "URL" like "javascript:initializeMe()"?
naivists
In my code, I call a callback from the applet (http://java.sun.com/products/plugin/1.3/docs/jsobject.html) to say "hello, I'm ready !" but I guess there are better ways to initialize applets released recently by Sun.
Laurent K