开发者

How to use java.util.Observable from Javascript?

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?


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.


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜