Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

javascript - Angular.js and Java Applet

I'm trying to call a java function via applet using Angular.js with no success. I'm not even getting the Applet loaded (java console is not starting when I load the app). I've used the approaches below without success. Any ideas?

Binding applet parameters with angularJS

angularjs and closing tags

PS: it's in Chrome and with the NPAPI enabled.

PS2: I get it with Knockout with the code below (we are migrating to Angular)

var res = document.getElementById("cdigApplet").signFile(file.id().toString(), "" , api.token);

signFile() is a method inside the Java Applet.

Html:

<applet id="cdigApplet" code="cdig.CDigApplet" archive="cdig-applet-1.0.jar, cdig-0.3.jar, json-20141113.jar" width="1" height="1" classloader_cache="false">
<param name="persistState" value="false" />
<param name="cache_option" value="no"/>

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We got it with the code below:

index.html

<script>
    <!-- applet id can be used to get a reference to the applet object -->
    var attributes = { id:'cdigApplet', code:'cdig.CDigApplet', archive:'cdig-applet-1.0.jar, cdig-0.3.jar, json-20141113.jar', width:1, height:1, classloader_cache:'false'} ;
    var parameters = {persistState: false, cache_option:'no' } ;
    deployJava.runApplet(attributes, parameters, '1.8');
</script>

signController.js

(function() {
    'use strict';

    angular
        .module('app')
        .controller('signController', signController);

    signController.$inject = ['$rootScope', '$scope','listFactory', 'infoService'];

    /* @ngInject */
    function signController($rootScope, $scope, listFactory, infoService) {
        var vm = this;
        var token = $rootScope.token;
        $scope.name = infoService.getName;

        ////////////////

        $scope.signFile = function () {
            var fileId = infoService.getId();
            var Id = fileId.toString();
            var res = document.getElementById("cdigApplet").signFile(Id, '', token);            

            var json = JSON.parse(res);
            if (json.success === true)
            {
                alert("Documento assinado com sucesso! Clique em 'Abrir' para ver a assinatura.");
                $('#sign').modal('hide');
            }
            else
            {
                alert("Documento n?o assinado!
" + json.message);
                $('#sign').modal('hide');
            }
        };
    }
})();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...