如何从 Javascript 使用 java.util.Observable?
我正在构建一个 Drupal 模块,它将“FileCatalyst”Java FTP 小程序与标准 Drupal 表单集成在一起。我正在实现一个挂钩,以便在文件传输完成时提交表单。目前,我正在使用 setTimeout() 调用轮询小程序,但如果状态更改发生得太快,此方法可能会错过状态更改。
然而,FileCatalyst 对象继承自 java.util.Observable – 因此显然可以为 applet 注册观察者并获取状态更改的通知。我想知道如何实现这一点。
我可以使用 Javascript 中的 document.FileCatalyst.addObserver(obj) 函数将这些状态更改发送到 Javascript 对象吗?我应该向 addObserver 传递什么?如何构建观察者?观察者需要实现哪些方法才能接收状态更改通知?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我无法完全回答你的问题,但我读到 java.util.Observable 有一个黑暗的一面(参见 Head First Design Patterns)。也就是说,Observable 必须纳入类层次结构中。 java.beans中的PropertyListener适合您的使用场景吗?如果是这样,有很多示例代码展示了如何为普通的旧 JavaBean 设置 PropertyListener。
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.
每个 Java applet 也是一个 Javascript 对象,提供与 Java 对象相同的方法。因此,您可以从 Javascript 调用 addObserver()。作为参数传递的对象
应该是一个 Javascript 对象,提供与 Observer 类型指定的方法相同的方法(假设 addObserver() 采用 Observer 类型的单个参数)。
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).
您需要使用 fcupload.js 中提供的重定向 URL。例如:
var callurlaftertransfer = "javascript:submitForm()";
然后你可以让submitForm()函数进行像document.myform.submit()这样的调用;
希望有帮助!
克里斯
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