Executing a method in an applet using JavaScript

I am trying to print some information using an applet. The applet is located in the signed qds-client.jar file and has the following code:

public class PrintText extends Applet  implements Printable {

 private ClientAccount clientAccount;

 public ClientAccount getClientAccount() {
     return clientAccount;
 }

 public void setClientAccount (ClientAccount clientAccount) {
     this.clientAccount = clientAccount;
 }

 public void setClientAccountFromJSON(String json) {
     this.clientAccount = toClientAccountFromJSON(json);
     System.out.println("------------------------------SetClient");
 }

 public int print(Graphics g, PageFormat format, int page) throws
         ...
 }

 public void printText() throws PrinterException {
     ...
 }

 private String getTextToPrint(ClientAccount clientAccount) throws PrinterException {
     ...
 }

 private ClientAccount toClientAccountFromJSON(String json) {
     return JsonUtils.fromJson(ClientAccount.class, json);
 }

 public void startPrint () {
     System.out.println("------------------------------------------Start");
 }
}

The JNLP configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.5+" codebase="http://localhost:10099/partials/" href="print.jnlp">
    <information>
       ....
    </information>

<resources>
    <jar href="/partials/qds-client.jar"/>
    <jar href="/partials/core-3.2.1.jar"/>
    <jar href="/partials/gson-2.3.1.jar"/>
</resources>

<applet-desc name="printText" main-class="com.qdsrest.utils.printer.PrintText" width="500" height="200"></applet-desc>

<update check="background"/>
<security>
    <all-permissions/>
</security>

Including the HTML tag for the applet:

<applet name="printApplet" jnlp_href="/partials/print.jnlp" width="10" height="10">
<param name="permissions" value="all-permissions"/>
</applet>

However, when I call a method from the applet in a JavaScript file like this:

document.printApplet.setClientAccountFromJSON({/not empty/});

I encounter the following error messages:

Error: Error calling method on NPObject!

In Mozilla and

basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory: try again ..

In Java Console. It seems that the method isn't working properly. Why am I getting "try again .." messages? What do they mean? The method toClientAccountFromJSON uses the GSON library gson-2.3.1.jar, which successfully deserializes JSON objects into Java objects. What could be causing these issues? Please advise on the correct approach.

Answer №1

Back in the days of the first browser wars, I vaguely remember a time when applets required an attribute called mayscript to communicate with javascript.

Also, don't forget that the parameter must be a string:

 setClientAccountFromJSON("somestring or stringvar");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modifying the Color of Individual Items within the Pagination Component in MUI

I am attempting to modify the background color of every item in my Pagination component by utilizing makeStyles. import { Pagination } from "@material-ui/lab"; import { makeStyles } from "@material-ui/core"; const pagination = makeStyl ...

Having trouble figuring out how to update a list using ajax in Yii

I need to modify a JavaScript function that filters the content of a list. The current code looks like this: var id = $(this).data('id'); $.fn.yiiListView.update('contests-list', { data: {category: 2} }); I couldn't find any ...

Display/Conceal WP Submenu

Struggling to switch the behavior of my Wordpress menu. Want it to display when clicked, not when hovered: <nav> <ul> <li> <?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ...

What is the proper method for activating the lights in a traffic light sequence?

I've been working on creating a traffic light sequence where each time the "change lights" button is pressed, the light is supposed to change. However, I'm facing an issue where the code only displays the red light and doesn't switch to ambe ...

Error encountered in SelectInput.js file of React MUI 4: line 340 - TypeError: Unable to access properties of undefined (specifically 'value')

An issue arises when an empty array is provided as the options. The error message: SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading 'value') at SelectInput.js:340:1 at Array.map (<anonymous>) ...

What seems to be the issue with the data initialization function not functioning properly within this Vue component?

In my Vue 3 component, the script code is as follows: <script> /* eslint-disable */ export default { name: "BarExample", data: dataInitialisation, methods: { updateChart, } }; function dataInitialisation() { return { c ...

I encountered an error while trying to deploy my next.js project on Vercel - it seems that the module 'react-icons/Fa' cannot be found, along with

I'm currently in the process of deploying my Next.js TypeScript project on Vercel, but I've encountered an error. Can someone please help me with fixing this bug? Should I try running "npm run build" and then push the changes to GitHub again? Tha ...

A guide on utilizing ng-repeat to iterate through array values in Views

Need help with using ng-repeat on array values within an ng-repeat in VIEWS? The second ng-repeat is not functioning properly. Here is the value of generalDocument.documents: ["14-10-2015.xls","15-10-2015.xls","16-10-2015.xls"] <div class="box-body ...

Continuously incorporating Ajax requests into a queue

I'm currently tackling a new feature at work and find myself at a crucial point. Despite being unfamiliar with Ajax, I am determined to set up a manual queue to handle the requests instead of relying on the browser. After some research and referring t ...

Why is the Floating Action Button not showing the source image on Android Studio?

Issue with displaying source image on Floating Action Button Click here for an example of the problem ...

Can an array be duplicated while iterating through it in Java?

Is there a way to duplicate an array while iterating through it? I am looking for a method to pass a copy of the most recent elements added to the array while still in the loop, to another function within the class for further processing before returning ...

What are some ways to direct users from one page to another without relying on server-side programming?

Is there a way to create a redirect page using jQuery or JavaScript? What is the process of writing client-side scripting code to redirect the browser from one page (page1) to another page (page n)? ...

Can anyone guide me on creating a Mapbox map layer using React.js?

I'm currently in the process of creating a polygon layer on top of my Mapbox map using ReactMapboxGL. I have some Mapbox Javascript code that I need to convert into React.js format: map.on('load', function () { map.addLayer({ ...

In Three JS, shader x, y, z coordinates are based on the orientation of the object rather than the scene itself

Animating the x,y,z coordinates of vertices in a sphere-like manner with horizontal rings around the center using attributes on a THREE.Points() object has been quite intriguing. Initially, with a MeshStandardMaterial(), tilting the Points object along the ...

What are the steps to analyzing server logs in real-time with Java code while processes are running, and then displaying the information on a user interface?

Is there a way to fetch and display console log information from the server in real-time or for completed processes using Java programming? ...

data retrieval not refreshing sorting post construction

My challenge involves fetching data from MongoDB with sorting. While it works perfectly on the development server, it fails to update the data after being built and hosted. import Review from "@/models/review"; import connectdb from "@/util/ ...

Switch out a new js file every time the page is reloaded

I have a JS file with various objects (var), and I'm looking to dynamically load a different object each time the page is loaded. For instance, upon page load, a new object 'temp' should be created with data from one of the objects in the JS ...

What is the process for calling app.vue methods from an ES6 module?

I am currently in the process of constructing a vuejs application using webpack, vuex, and vue-router. The organization of my project is as follows: [components] BlockingLayer.vue [store] index.js [restapi] index.js App.vue main.js Within App. ...

Sorting tables in Jquery with advanced filter options and seamless integration with an ajax pager

I've implemented a tablesorter library for sorting and filtering data in a table along with a plugin that allows me to paginate the table across multiple pages. Due to the increasing number of records in my table causing slow loading times (>60 se ...

Automate webpage opening and saving using Selenium in Java

I am currently working on a project where I need to extract content from various web pages, such as "". However, I am facing a challenge because simply using URL and BufferReader libraries does not provide me with the full content - only the frame of the p ...