简体   繁体   English

如何在ReactJS中使用Java Applet

[英]How to use java applet in reactjs

I'm trying to integrate a specific java applet in my reactjs application. 我正在尝试在我的reactjs应用程序中集成一个特定的Java小程序。 More over, I would like to make it run in a Dialog (using matelial UI). 而且,我想使其在对话框中运行(使用材质UI)。

I have a render function which works and when I click on a specific button, the Dialog is shown. 我有一个可以使用的渲染功能,当我单击特定按钮时,将显示对话框。 The code concerning the applet part in the Dialog of my return() function is shown here : 我的return()函数对话框中有关applet部分的代码如下所示:

<Dialog
      ref="dialogAction"
      title={this.state.dialogTitle}
      actions={customAction}
      actionFocus="submit"
      modal={this.state.modal}
      autoDetectWindowHeight={true}
      autoScrollBodyContent={true}
      contentStyle={styles.dialogMarvin}>

       <applet
        type="application/x-java-applet;version=1.6"
        width="540"
        height="480"
        codebase="./marvin"
        archive="appletlaunch.jar"
        code="chemaxon/marvin/applet/JMSketchLaunch"
        legacy_lifecycle={true}
        java-vm-args="-Djnlp.packEnabled=true -Xmx512m"
        codebase_lookup={false}>

        </applet>

      </Dialog>

When I run this code, the Dialog is shown as expected and the first time, firefox ask me if I want to activate java (telling me that it's working so far). 当我运行此代码时,对话框将按预期显示,并且是第一次,firefox询问我是否要激活Java(告诉我到目前为止它正在工作)。 Watch the following picture: applet ready to be loaded, but allowance asked 观看下图: 准备加载小程序,但要求津贴

But once java allowed, nothing is displayed (only blank, look the following image: once allowance granted ). 但是,一旦允许使用Java,就不会显示任何内容(只有空白,请看下面的图像: 一旦授予了许可 )。 If I check the code in the brower, some properties are missing. 如果我在浏览器中检查代码,则缺少某些属性。 Instead of the original embeded code I have this one (missing archive, codebase and some other) : 而不是原始的嵌入代码,我有了这个代码(缺少归档文件,代码库和其他代码):

<applet 
   type="application/x-java-applet;version=1.6"
   data-reactid=".0.$=12:0.0.2.2.0.$=10.0.1.0"
   height="480"
   width="540">
</applet>

Some inforamtions are displayed but I don't understand them yet. 显示了一些信息,但我还不了解。

Have you arleady try to emmbed an applet in your reactjs ? 您有没有试图在自己的reactjs中嵌入小程序? Have you some tips to give ? 您有一些建议要给吗? I'm doing something wrong ? 我做错了吗?

React is picky when it comes to allowing random attribute names. 在允许使用随机属性名称时,React很挑剔。 So instead of injecting applet by using JSX, just set the innerHTML of the component instead. 因此,与其使用JSX注入applet ,不如设置该组件的innerHTML。 To do this, use React's dangerouslySetInnerHTML : 为此,请使用React的dangerouslySetInnerHTML SetInnerHTML:

var dangerousMarkup = {
  __html: '<applet.... ' // the whole markup string you want to inject
};

<div dangerouslySetInnerHTML={dangerousMarkup}></div>

This is basically the same as setting domNode.innerHTML = '<applet...' with vanilla javascript, and React just let's the raw markup pass through without modification. 这基本上与使用普通javascript设置domNode.innerHTML = '<applet...'相同,React只是让原始标记通过而无需修改。

Docs: https://facebook.github.io/react/tips/dangerously-set-inner-html.html 文件: https//facebook.github.io/react/tips/dangerously-set-inner-html.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM