views:

114

answers:

3

I'm building a Drupal module that integrates the "FileCatalyst" Java FTP applet with a standard Drupal form. I'm implementing a hook to submit the form when a file transfer completes. Currently I'm polling the applet with a setTimeout() call, but this method can miss changes of state if they happen too fast.

However, the FileCatalyst object inherits from java.util.Observable – so it's apparently possible to register an observer for the applet and get notifications of state-changes. I'd like to know how to implement this.

Can I use the document.FileCatalyst.addObserver(obj) function from Javascript to get these state-changes sent to a Javascript object? What do I pass to addObserver? How do I construct the observer? What methods does the observer need to implement in order to receive state-change notifications?

A: 

I can't fully answer your question, but I've read that there is a dark side to java.util.Observable (see Head First Design Patterns). Namely, the Observable must be worked into the class hierarchy. Would the PropertyListener in java.beans suit your usage scenario? If so, there is a lot of sample code that shows how to set up the PropertyListeners for a plain old JavaBean.

darren
A: 

Every Java applet is also a Javascript object offering the same methods as the Java object. Thus you can invoke addObserver() from Javascript. The object that you pass as a parameter should be a Javascript object offering the same methods as those specified by the Observer type (assuming addObserver() takes a single parameter of type Observer).

Itay
A: 

You need to use the redirect URLs provided in fcupload.js. For example:

var callurlaftertransfer = "javascript:submitForm()";

Then you would have the submitForm() function make a call like document.myform.submit();

Hope that helps!

Chris

Chris Bailey
That's a good answer and addresses the polling issue perfectly. (Don't know why I didn't do it that way in the first place!) The larger gist of my question is related to a spec I've been given to implement.The client already implemented a page with a form, plus the FileCatalyst applet below the form. They want the form to submit when files finish successfully uploading, and they want the file list to be sent along with the contents of the form. Unfortunately the callurlaftertransfer method doesn't include this data.(see next comment...)
Scott Lahteine
There's another FileCatalyst setting, "postURL" which includes the list of uploaded files, but it requires a page reload and would skip the form submission. I was hoping to get the list of files uploaded prior to any page reload, so it could be sent along with the form. (Embedding the applet in an iframe is one hackish solution I had considered.)In the end I convinced the client to change the spec. Namely, show the applet by itself as Step 1, capture the uploaded files from postURL, and then show the form as Step 2, which will then have the postURL information in a hidden field.
Scott Lahteine